2016-06-08 45 views
1

我用攝像機標定在MATLAB中檢測到一些棋盤圖案,之後轉型攝像機標定模式

figure; showExtrinsics(cameraParams, 'CameraCentric'); 

enter image description here

現在,我想繞X軸,使得棋盤圖案它們在相機框架中具有幾乎相同的y座標。

方法: 我得到相機框架中所有圖案的位置。然後我做優化,其中目標函數是最小化y方差,變量是圍繞x範圍從0到360的旋轉。

問題: 但是當我繪製轉換後的y座標時,它們甚至幾乎處於一條線。

代碼:

獲取checkerboad點:

%% Get rotation and translation matrices for each image; 
T_cw=cell(num_imgs,1); % stores camera to world rotation and translation for each image 
pixel_coordinates=zeros(num_imgs,2); % stores the pixel coordinates of each checkerboard origin 
for ii=1:num_imgs, 
    % Calibrate the camera 
    im=imread(list_imgs_path{ii}); 
    [imagePoints, boardSize] = detectCheckerboardPoints(im); 
    [r_wc, t_wc] = extrinsics(imagePoints, worldPoints, cameraParams); 
    T_wc=[r_wc,t_wc';0 0 0 1]; 
    % World to camera matrix 
    T_cw{ii} = inv(T_wc); 
    t_cw{ii}=T_cw{ii}(1:3,4); % x,y,z coordinates in camera's frame 
end 

數據(num_imgs = 10):

t_cw 
[-1072.01388542262;1312.20387622761;-1853.34408157349] 
[-1052.07856598756;1269.03455126794;-1826.73576892251] 
[-1091.85978641218;1351.08261414473;-1668.88197803184] 
[-1337.56358084648;1373.78548638383;-1396.87603554914] 
[-1555.19509876309;1261.60428874489;-1174.63047408086] 
[-1592.39596647158;1066.82210015055;-1165.34417772659] 
[-1523.84307918660;963.781819272748;-1207.27444716506] 
[-1614.00792252030;893.962075837621;-1114.73528985018] 
[-1781.83112607964;708.973204727939;-797.185326205240] 
[-1781.83112607964;708.973204727939;-797.185326205240] 

主代碼(優化和轉換):

%% Get theta for rotation 
f_obj = @(x)var_ycors(x,t_cw); 
opt_theta = fminbnd(f_obj,0,360); 
%% Plotting (rotate ycor and check to fix theta) 
y_rotated=zeros(1,num_imgs); 
for ii=1:num_imgs, 
    y_rotated(ii)=rotate_cor(opt_theta,t_cw{ii}); 
end 
plot(1:numel(y_rotated),y_rotated); 


function var_computed=var_ycors(theta,t_cw) 
ycor=zeros(1,numel(t_cw)); 
for ii =1:numel(t_cw), 
    ycor(ii)=rotate_cor(theta,t_cw{ii}); 
end 
var_computed=var(ycor); 
end 

function ycor=rotate_cor(theta,mat) 
r_x=[1 0 0; 0 cosd(theta) -sind(theta); 0 sind(theta) cosd(theta)]; 
rotate_mat=mat'*r_x; 
ycor=rotate_mat(2); 
end 
+0

考慮接受答案,如果它幫助你 –

回答

1

這是一個明確的ei genvector問題!

把你的重心:

t_cw=[-1072.01388542262;1312.20387622761;-1853.34408157349 
-1052.07856598756;1269.03455126794;-1826.73576892251 
-1091.85978641218;1351.08261414473;-1668.88197803184 
-1337.56358084648;1373.78548638383;-1396.87603554914 
-1555.19509876309;1261.60428874489;-1174.63047408086 
-1592.39596647158;1066.82210015055;-1165.34417772659 
-1523.84307918660;963.781819272748;-1207.27444716506 
-1614.00792252030;893.962075837621;-1114.73528985018 
-1781.83112607964;708.973204727939;-797.185326205240 
-1781.83112607964;708.973204727939;-797.185326205240]; 
t_cw=reshape(t_cw,[3,10])'; 

計算PCA在他們身上,所以我們知道主要conponents:

[R]=pca(t_cw); 

而且....這就是它! R現在是原始點與旋轉座標系之間的轉換矩陣。作爲一個例子,我將紅色舊分和藍色的新的畫:

hold on 

plot3(t_cw(:,1),t_cw(:,2),t_cw(:,3),'ro') 
trans=t_cw*R; 
plot3(trans(:,1),trans(:,2),trans(:,3),'bo') 

enter image description here

你可以看到,現在藍色的是在一個平面上,用最好的擬合X方向。如果你想讓他們在Y方向,只需旋轉90度在Z(我相信你可以通過2分鐘的Google知道如何做到這一點))。

注意:這在數學上是最合適的。我知道他們並不像人們想要的那樣「連續」,但是這是因爲數據,這是最好的,因爲這是特徵向量!