본문 바로가기

VISION/Stereo Vision

Stereo Vision : Rectification 예제 (Matlab)

출처 : Matlab example

1. Rectification 이란?

스테레오 비전에서 2개의 카메라를 이용하여 같은 높이(same raw)에서 영상을 찍을 경우 

2D 문제가 1D 문제로 감소된다.  (그러나 실제적으로 같은 높이가 아닐 확률이 높을 것이다.)

Rectification 은 보통 dispatiry 를 계산하기 전의 전처리를 사용된다.

2개의 카메라로 동시에 찍었을 때 명백하게 방향 및 위치에 offset이 존재하는 것을 볼 수 있다.

rectification 의 목표는 연관된 점(point)들이 두 영상에서 같은 열(Row)에서 위치하도록 영상을 변환(Transform) 하는 것이다.

2. 각 영상에서 관련된 특징점을 찾자.

기본적으로 2 영상에서 관련된 즉, 같은 점이라고 생각되는 점들의 연관 정보가 있어야 한다.

Surf 등과 같은 특징점 찾기 알고리즘을 사용하자. 

blobs1 = detectSURFFeatures(I1gray, 'MetricThreshold', 2000);
blobs2 = detectSURFFeatures(I2gray, 'MetricThreshold', 2000);

단, SURF에 의해 찾아진 특징점들이 좌측 영상에 있다고, 우측 영상에 있으리라는 보장은 없다. 

3. 특징점들의 Feature를 찾고, 매칭한다.

[features1, validBlobs1] = extractFeatures(I1gray, blobs1);
[features2, validBlobs2] = extractFeatures(I2gray, blobs2);

여기서는 SAD (Sum of Absolute Difference) metric 을 이용한다.

indexPairs = matchFeatures(features1, features2, 'Metric', 'SAD', ...
  'MatchThreshold', 5);

각 영상에서 매칭된 점들만 살리자.

matchedPoints1 = validBlobs1(indexPairs(:,1),:);
matchedPoints2 = validBlobs2(indexPairs(:,2),:);

매칭된 점들을 비교해보자 대부분은 맞지만 여전히 Outlier 들이 존재한다.

4. 에피폴라 구속조건(Epipolar constraint)을 이용하여 Outlier들을 제거한다.

매칭된 점들은 상호간 에피폴라 구속 조건을 만족해야 한다. 즉, 점은 다른 영상에서 에피폴라 라인상에 위치해야한다는 의미이다. 이를 위해 먼저 Fundamental Matrix를 찾자. 에피폴이 영상내에 있는지 확인한다. (영상내에 에피폴이 있으면 오류)

tip : Matlab norm8Point 방법 이용시 inliers 는 걸러주지 않고 모든 대상임.

[fMatrix, epipolarInliers, status] = estimateFundamentalMatrix(...
  matchedPoints1, matchedPoints2, 'Method', 'RANSAC', ...
  'NumTrials', 10000, 'DistanceThreshold', 0.1, 'Confidence', 99.99);

if status ~= 0 || isEpipoleInImage(fMatrix, size(I1)) ...
  || isEpipoleInImage(fMatrix', size(I2))
  error(['Either not enough matching points were found or '...
         'the epipoles are inside the images. You may need to '...
         'inspect and improve the quality of detected features ',...
         'and/or improve the quality of your images.']);
end

inlierPoints1 = matchedPoints1(epipolarInliers, :);
inlierPoints2 = matchedPoints2(epipolarInliers, :);

figure;
showMatchedFeatures(I1, I2, inlierPoints1, inlierPoints2);
legend('Inlier points in I1', 'Inlier points in I2');

 

5. 영상들을 교정(Rectify) 하자.

 Rectification transformatinon 을 계산한다. (estimateUncalibratedRectification function)

관련된 점들을 같은 Row로 변환해 줄 것이다.

[t1, t2] = estimateUncalibratedRectification(fMatrix, ...
  inlierPoints1.Location, inlierPoints2.Location, size(I2));
tform1 = projective2d(t1);
tform2 = projective2d(t2);

 

6. 교정과정(Rectification Process)를 일반화하자.

위의 과정은 같은 열(Same Raw)일 경우이므로 일반화해보자.

cvexRectifyImages('parkinglot_left.png', 'parkinglot_right.png');

 

'VISION > Stereo Vision' 카테고리의 다른 글

Stereo Vision : Rectification  (0) 2022.04.17
Stereo Vision : Match  (0) 2022.02.05
Stereo Vision : 8 Point Algorithm (Find Fundamental Mat)  (0) 2022.02.02
Stereo Vision : Triangulation  (0) 2022.01.22