Main Content

특징을 사용하여 두 포인트 클라우드 간의 변환 추정

이 예제에서는 두 포인트 클라우드 간의 강체 변환을 추정하는 방법을 보여줍니다. 이 예제의 경우는 추정에 필요한 점 개수를 대폭 줄이기 위해 특징 추출과 특징 매칭을 사용합니다. extractFPFHFeatures 함수를 사용하여 포인트 클라우드에서 FPFH(빠른 특징점 히스토그램) 특징을 추출한 후 pcmatchfeatures 함수를 사용하여 추출한 특징에서 일치 항목을 검색합니다. 마지막으로, estgeotform3d 함수 및 일치하는 특징을 사용하여 강체 변환을 추정합니다.

전처리

입력 포인트 클라우드에 강체 변환을 적용하여 2개의 포인트 클라우드를 만듭니다.

포인트 클라우드 데이터를 작업 공간으로 읽어옵니다.

rng("default")
ptCld = pcread("highwayScene.pcd");
ptCld.Count
ans = 65536

약 65,000개의 점을 포함하고 있으므로 계산 속도를 개선하기 위해 포인트 클라우드를 다운샘플링합니다.

ptCloud = pcdownsample(ptCld,gridAverage=0.2);
ptCloud.Count
ans = 24596

30도 회전과 x 좌표축 및 y 좌표축에서 5단위 평행 이동을 갖는 강체 변환 행렬을 만듭니다.

rotAngle = 30;
trans = [5 5 0];
tform = rigidtform3d([0 0 rotAngle],trans);

입력 포인트 클라우드를 변환합니다.

ptCloudTformed = pctransform(ptCloud,tform);

두 포인트 클라우드를 시각화합니다.

pcshowpair(ptCloud,ptCloudTformed)
axis on
xlim([-50 75])
ylim([-40 80])
legend("Original","Transformed",TextColor=[1 1 0])

Figure contains an axes object. The axes object contains 2 objects of type scatter. These objects represent Original, Transformed.

특징 추출 및 정합

extractFPFHFeatures 함수를 사용하여 두 포인트 클라우드에서 특징을 추출합니다.

fixedFeature = extractFPFHFeatures(ptCloud);
movingFeature = extractFPFHFeatures(ptCloudTformed);

일치하는 특징을 찾고 일치하는 쌍의 개수를 표시합니다.

[matchingPairs,scores] = pcmatchfeatures(fixedFeature,movingFeature, ...
    ptCloud,ptCloudTformed,Method="Exhaustive");
length(matchingPairs)
ans = 1814

포인트 클라우드에서 일치하는 점들을 선택합니다.

fixedPts = select(ptCloud,matchingPairs(:,1));
matchingPts = select(ptCloudTformed,matchingPairs(:,2));

일치하는 점들을 사용하여 변환 행렬을 추정합니다.

estimatedTform = estgeotform3d(fixedPts.Location, ...
    matchingPts.Location,"rigid");
disp(estimatedTform.A)
    0.8660   -0.5000   -0.0003    4.9995
    0.5000    0.8660    0.0000    5.0022
    0.0002   -0.0002    1.0000    0.0020
         0         0         0    1.0000

정의된 변환 행렬을 표시합니다.

disp(tform.A)
    0.8660   -0.5000         0    5.0000
    0.5000    0.8660         0    5.0000
         0         0    1.0000         0
         0         0         0    1.0000

추정된 변환을 사용하여 ptCloudTformed를 다시 초기 포인트 클라우드로 재변환합니다.

ptCloudTformed = pctransform(ptCloudTformed,invert(estimatedTform));

두 포인트 클라우드를 시각화합니다.

pcshowpair(ptCloud,ptCloudTformed)
axis on
xlim([-50 50])
ylim([-40 60])
title("Aligned Point Clouds")

Figure contains an axes object. The axes object with title Aligned Point Clouds contains 2 objects of type scatter.