728x90
반응형
function [T1,T2,Pn1,Pn2] = rectify(Po1,Po2)
% RECTIFY compute rectification matrices
%
% [T1,T2,Pn1,Pn2] = rectify(Po1,Po2) computes the
% rectifying projection matrices "Pn1", "Pn2", and
% the rectifying transformation of the retinal plane
% "T1", "T2" (in homogeneous coordinate). The arguments
% are the two old projection matrices "Po1" and "Po2".
% focal lenght
% (extp(a,b) is external product of vectors a,b)
au = norm(extp(Po1(1,1:3)', Po1(3,1:3)'));
av = norm(extp(Po1(2,1:3)', Po1(3,1:3)'));
% optical centres
c1 = - inv(Po1(:,1:3))*Po1(:,4);
c2 = - inv(Po2(:,1:3))*Po2(:,4);
% retinal planes
fl = Po1(3,1:3)';
fr = Po2(3,1:3)';
nn = extp(fl,fr);
% solve the four systems
A = [ [c1' 1]' [c2' 1]' [nn' 0]' ]';
[U,S,V] = svd(A);
r = 1/(norm(V([1 2 3],4)));
a3 = r * V(:,4);
A = [ [c1' 1]' [c2' 1]' [a3(1:3)' 0]' ]';
[U,S,V] = svd(A);
r = norm(av)/(norm(V([1 2 3],4)));
a2 = r * V(:,4);
A = [ [c1' 1]' [a2(1:3)' 0]' [a3(1:3)' 0]' ]';
[U,S,V] = svd(A);
r = norm(au)/(norm(V([1 2 3],4)));
a1 = r * V(:,4);
A = [ [c2' 1]' [a2(1:3)' 0]' [a3(1:3)' 0]' ]';
[U,S,V] = svd(A);
r = norm(au)/(norm(V([1 2 3],4)));
b1 = r * V(:,4);
% adjustment
H = [
1 0 0
0 1 0
0 0 1 ];
% rectifying projection matrices
Pn1 = H * [ a1 a2 a3 ]';
Pn2 = H * [ b1 a2 a3 ]';
% rectifying image transformation
T1 = Pn1(1:3,1:3)* inv(Po1(1:3,1:3));
T2 = Pn2(1:3,1:3)* inv(Po2(1:3,1:3));
스테레오 쌍 이미지를 왜곡하는 정류 알고리즘입니다. 이 코드는 매트랩 코드이고 C언어에서 구현한 버전이 있다고 하는데 링크가 사라졌네요 있으신분 댓글 남겨주시면 감사하겠습니다. 아래는 적용 결과입니다 윗줄이 스테레오 쌍 이미지고 아랫줄이 왜곡된 이미지입니다.
728x90
반응형
'코드' 카테고리의 다른 글
[face recognition] Adaface : Quality Adaptive Margin for Face Recognition (0) | 2024.03.11 |
---|---|
[matlab] 이미지 리사이즈 코드 (0) | 2023.03.20 |
[python] 이미지 증강 코드 data augmentaion (0) | 2023.03.20 |
[python] Fashion mnist mlp (0) | 2023.02.24 |
[python] 말과 사람 구분하기 horse or human (0) | 2023.02.24 |