5

サイドコンディション(MatLab)を使用して、カメラ画像の2Dピクセル座標から3D座標を再構築しようとしています。私は外因性と内因性のカメラパラメータを持っています。

同種変換を使用して、3D座標を初期の世界座標系からカメラ座標系に変換できます。したがって、ここに、変換行列R_world_to_Cameraに外部パラメーターがあります。

R_world_to_Camera = [ r_11, r_12, r_13, t1;
r_21, r_22, r_23, t2;
r_31, r_32, r_33, t3;
0, 0, 0, 1];

固有のパラメーターについては、Caltechの「MatLab用カメラキャリブレーションツールボックス」を使用して、次のパラメーターを取得しました。

Calibration results (with uncertainties): 

 Focal Length:          fc = [ 1017.21523   1012.54901 ] ± [ NaN   NaN ] 
 Principal point:       cc = [ 319.50000   239.50000 ] ± [ NaN   NaN ] 
 Skew:             alpha_c = [ 0.00000 ] ± [ NaN  ]   => angle of pixel axes = 90.00000 ± NaN degrees 
 Distortion:            kc = [ 0.00000   0.00000   0.00000   0.00000  0.00000 ] ± [ NaN   NaN   NaN   NaN    NaN ] 
 Pixel error:          err = [ 0.11596   0.14469 ] 

 Note: The numerical errors are approximately three times the standard deviations (for reference).

次に、Camera-Calibration-Matrix K(3x3)を取得します。

K = [1.017215234570303e+03, 0, 3.195000000000000e+02; 
0, 1.012549014668498e+03,2.395000000000000e+02; 
0, 0, 1.0000];

これを使用して、3D-> 2D --Projection-Matrix P(3x4)を次のように計算できます。

P = K * [eye(3), zeros(3,1)];

World-Coordinates [X、Y、Z] _Worldのポイントを変換するとき、最初にそれをCamera-Coordinatesに変換してから、2Dに投影します。

% Transformation
P_world = [X; Y; Z; 1]; % homogenous coordinates in World coordinate System
P_camera = R_world_to_Camera * [X; Y; Z; 1];

% Projection
P_pixels = P * camera;
P_pixels = P_pixels / P_pixels(3); % normalize coordinates

だから私の質問は今これらのステップを逆にする方法ですか?副次的な条件として、Z座標を既知(世界座標ではゼロ)に設定したいと思います。Stackoverflowでここで提案されたソリューションを試しましたが、どういうわけか間違った座標を取得します。何か案が?すべての助けは大歓迎です!

4

2 に答える 2

8

一般に、この手順を逆にすることはできません。3Dポイントを2D画像に投影すると、深度とスケールの情報が失われます。ただし、ご指摘のとおり、すべての3DポイントがZ = 0平面上にある場合、それらを投影から戻すのは簡単です。カメラ行列の逆Ki = K ^ -1を計算し、それをイメージポイントに適用します。同次座標で。

P_camera = Ki * [u、v、1] '

ここで、[u、v]は画像の座標であり、アポストロフィは転置を示します。必要な3Dポイントは、カメラの中心からP_cameraの光線上にあります。両方を世界座標で表現します。

P_world = [R | t] _camera_to_world * [P_camera、1] '

C_world = [R | t] _camera_to_world * [0、0、0、1] '

ここで、[R|t]は4x4座標変換です。ここで、各光線上の点のセットは次のように表されます。

P =C_world+ラムダ*P_world;

ここで、lambdaはスカラー(光線に沿った座標)です。これで、P(3)= 0の条件を課して、ポイントをZ=0平面に配置するラムダの値を見つけることができます。

于 2012-07-05T02:39:57.460 に答える
7

赤ワインと徹底的な読書のおかげで、(ドイツ語の)修士論文で答えを見つけました:)私の「テストコード」は次のとおりです。

% Clean-Up First 
clear all; 
close all; 
clc; 

% Caamera-Calibration-Matrix
 K = [1.017215234570303e+03, 0, 3.195000000000000e+02, 0; 
0, 1.012549014668498e+03,2.395000000000000e+02, 0; 
0, 0, 1.0000, 0; 
0, 0, 0, 0]; 

% Transforma Matrix from 3D-World-Coordinate System to 3D-Camera-Coordinate System (Origin on CCD-Chip) 
% 
% The Camera is oriented "looking" into positive X-Direction of the World-Coordinate-System. On the picture,
% positive Y-Direction will be to the left, positive Z-Direction to the top. (right hand coordinate system!)
 R_World_to_Cam = [-0.0113242625465167   -0.999822053685344   0.0151163536128891   141.173585444427; 
0.00842007509644635   -0.0152123858102325   -0.999848810645587   1611.96528372161; 
0.999900032304804   -0.0111955728474261   0.00859117128537919   847.090629282911; 
0   0   0   1]; 

% Projection- and Transforma Matrix P 
 P = K * R_World_to_Cam; 

% arbitrary Points X_World in World-Coordinate-System [mm] (homogenous Coordinates) 
% forming a square of size 10m x 4m 
 X_World_1 = [20000; 2000; 0; 1]; 
 X_World_2 = [20000; -2000; 0; 1]; 
 X_World_3 = [10000; 2000; 0; 1]; 
 X_World_4 = [10000; -2000; 0; 1]; 

% Transform and Project from 3D-World -> 2D-Picture 
 X_Pic_1 = P * X_World_1; 
 X_Pic_2 = P * X_World_2; 
 X_Pic_3 = P * X_World_3; 
 X_Pic_4 = P * X_World_4; 

% normalize homogenous Coordinates (3rd Element has to be 1!) 
 X_Pic_1 = X_Pic_1 / X_Pic_1(3); 
 X_Pic_2 = X_Pic_2 / X_Pic_2(3); 
 X_Pic_3 = X_Pic_3 / X_Pic_3(3); 
 X_Pic_4 = X_Pic_4 / X_Pic_4(3); 

% Now for reverse procedure take arbitrary points in Camera-Picture... 
% (for simplicity, take points from above and "go" 30px to the right and 40px down) 
 X_Pic_backtransform_1 = X_Pic_1(1:3) + [30; 40; 0]; 
 X_Pic_backtransform_2 = X_Pic_2(1:3) + [30; 40; 0]; 
 X_Pic_backtransform_3 = X_Pic_3(1:3) + [30; 40; 0]; 
 X_Pic_backtransform_4 = X_Pic_4(1:3) + [30; 40; 0]; 

% ... and transform back following the formula from the Master Thesis (in German):
% Ilker Savas, "Entwicklung eines Systems zur visuellen Positionsbestimmung von Interaktionspartnern" 
 M_Mat = P(1:3,1:3);                 % Matrix M is the "top-front" 3x3 part 
 p_4 = P(1:3,4);                     % Vector p_4 is the "top-rear" 1x3 part 
 C_tilde = - inv( M_Mat ) * p_4;     % calculate C_tilde 

% Invert Projection with Side-Condition ( Z = 0 ) and Transform back to 
% World-Coordinate-System 
 X_Tilde_1 = inv( M_Mat ) * X_Pic_backtransform_1; 
 X_Tilde_2 = inv( M_Mat ) * X_Pic_backtransform_2; 
 X_Tilde_3 = inv( M_Mat ) * X_Pic_backtransform_3; 
 X_Tilde_4 = inv( M_Mat ) * X_Pic_backtransform_4; 

 mue_N_1 = -C_tilde(3) / X_Tilde_1(3); 
 mue_N_2 = -C_tilde(3) / X_Tilde_2(3); 
 mue_N_3 = -C_tilde(3) / X_Tilde_3(3); 
 mue_N_4 = -C_tilde(3) / X_Tilde_4(3); 

% Do the inversion of above steps... 
 X_World_backtransform_1 = mue_N_1 * inv( M_Mat ) * X_Pic_backtransform_1 + C_tilde; 
 X_World_backtransform_2 = mue_N_2 * inv( M_Mat ) * X_Pic_backtransform_2 + C_tilde; 
 X_World_backtransform_3 = mue_N_3 * inv( M_Mat ) * X_Pic_backtransform_3 + C_tilde; 
 X_World_backtransform_4 = mue_N_4 * inv( M_Mat ) * X_Pic_backtransform_4 + C_tilde; 


% Plot everything
figure(1); 
% First Bird Perspective of World-Coordinate System... 
subplot(1,2,1); 
xlabel('Y-World'); 
ylabel('X-World'); 
grid on; 
axis([-3000 3000 0 22000]); 
hold on; 


plot( -X_World_1(2), X_World_1(1), 'bo' ); 
plot( -X_World_2(2), X_World_2(1), 'bo' ); 
plot( -X_World_3(2), X_World_3(1), 'bo' ); 
plot( -X_World_4(2), X_World_4(1), 'bo' ); 
line([-X_World_1(2) -X_World_2(2) -X_World_4(2) -X_World_3(2) -X_World_1(2)], [X_World_1(1) X_World_2(1) X_World_4(1) X_World_3(1) X_World_1(1)], 'Color', 'blue' ); 

plot( -X_World_backtransform_1(2), X_World_backtransform_1(1), 'ro' ); 
plot( -X_World_backtransform_2(2), X_World_backtransform_2(1), 'ro' ); 
plot( -X_World_backtransform_3(2), X_World_backtransform_3(1), 'ro' ); 
plot( -X_World_backtransform_4(2), X_World_backtransform_4(1), 'ro' ); 
line([-X_World_backtransform_1(2) -X_World_backtransform_2(2) -X_World_backtransform_4(2) -X_World_backtransform_3(2) -X_World_backtransform_1(2)], [X_World_backtransform_1(1) X_World_backtransform_2(1) X_World_backtransform_4(1) X_World_backtransform_3(1) X_World_backtransform_1(1)], 'Color', 'red' ); 


hold off; 

% ...then the camera picture (perspective!)
subplot(1,2,2); 
hold on; 
image(ones(480,640).*255); 
colormap(gray(256)); 
axis([0 640 -480 0]); 
line([X_Pic_1(1) X_Pic_2(1) X_Pic_4(1) X_Pic_3(1) X_Pic_1(1)], -1*[X_Pic_1(2) X_Pic_2(2) X_Pic_4(2) X_Pic_3(2) X_Pic_1(2)], 'Color', 'blue' ); 
line([X_Pic_backtransform_1(1) X_Pic_backtransform_2(1) X_Pic_backtransform_4(1) X_Pic_backtransform_3(1) X_Pic_backtransform_1(1)], -1*[X_Pic_backtransform_1(2) X_Pic_backtransform_2(2) X_Pic_backtransform_4(2) X_Pic_backtransform_3(2) X_Pic_backtransform_1(2)], 'Color', 'red' ); 
hold off;
于 2012-07-06T17:48:27.303 に答える