Problem with XYZ points obtained

Hello,
I'm trying to get the XYZ coordenates of the world using the CameraCalibrator app from 200 segmented images obtained from the capture of an object pointed with a laser line and positioned on a platform that rotates 1.8 degrees (by capture) to subsequently generate a 3d model.
To calculate the calibration matrix with the rotation of the object, I used the following lines of code:
%%
angleX = 0;
angleY = stp*(1.8); >> stp is number of step of the platform
angleZ = 0;
Rx = rotx(angleX); Ry = roty(angleY); Rz = rotz(angleZ);
Rb = Rx*Ry*Rz;
tx = 0; ty = 0; tz = 0;
tb = [tx ty tz];
MPb = [Rb zeros(3,1); tb 1];
Rt = [RotationMatrix; TranslationVector];
MC = Rt*IntrinsicMatrix;
P = MPb*MC;
P = P';
%%
after that, with the points (u, v) obtained from the segmented image, I calculate the XYZ points of the world using the following lines of code:
%%
% (u*P31 - P11)X + (u*P32 - P12)Y + (u*P33 - P13)Z + (u*P34 - P14) = 0
% (v*P31 - P21)X + (v*P32 - P22)Y + (v*P33 - P23)Z + (v*P34 - P24) = 0
for i = 1:length([u,v]) >> this is the cycle only for an image
A = [(u(i)*P(3,1) - P(1,1)) (u(i)*P(3,2) - P(1,2)) (u(i)*P(3,3) - P(1,3));
(v(i)*P(3,1) - P(2,1)) (v(i)*P(3,2) - P(2,2)) (v(i)*P(3,3) - P(2,3))];
b = [-(u(i)*P(3,4)) + P(1,4);
-(v(i)*P(3,4)) + P(2,4)];
x = pinv(A)*b;
XYZ(i,:) = x;
end
%%
When I plot the points obtained (plot_points_XYZ.png), it doesn't resemble the real shape of the object (Cap_cam1_step_01.png).
What am I doing wrong?
Thank you for your help
Rod Hid
P.S: Are the distortion values incorporated into the calculations of the intrinsic matrix, rotation matrix and translation vector delivered by the CameraCalibrator app?

17 件のコメント

Adam Danz
Adam Danz 2019 年 5 月 9 日
I formatted your code. In the future, please use this button to add formatted code.
190509 092002-funtion handle in for loop - MATLAB Answers - MATLAB Central.jpg
Rod Hid
Rod Hid 2019 年 5 月 9 日
Ok, thanks.
darova
darova 2019 年 5 月 9 日
Can you please attach your data?
Rod Hid
Rod Hid 2019 年 5 月 10 日
Here are the calibration data of the camera, the XYZ points obtained and the complete code.
If you need the segmented images, you tell me.
darova
darova 2019 年 5 月 10 日
Can you please attach this data in another .mat . Can't read calibrationSession.mat (maybe i have older MATLAB version). Attach a few images also (not all)
TranslationVector = cameraParams.TranslationVectors(1,:);
RotationMatrix = double(cameraParams.RotationMatrices(:,:,1));
IntrinsicMatrix = cameraParams.IntrinsicMatrix();
I think something is wrong here:
img = imread(imgname); %Cargar imagen esqueletizada
[u,v] = find(img == 1); % u,v - vectors of 1xn length (rows)
for i = 1:length([u,v]) % has to be 1:length(u)
% some operations with u and v
end
Rod Hid
Rod Hid 2019 年 5 月 10 日
darova
darova 2019 年 5 月 10 日
Capture.PNG
Can you please attach those matrix in separate files
TranslationVector = cameraParams.TranslationVectors(1,:);
RotationMatrix = double(cameraParams.RotationMatrices(:,:,1));
IntrinsicMatrix = cameraParams.IntrinsicMatrix();
Rod Hid
Rod Hid 2019 年 5 月 11 日
I attach translation vector, rotation matrix and intrinsic matrix in separates files.
darova
darova 2019 年 5 月 11 日
I changed diagonal elements that respons for scale
IntrinsicMatrix(1) = IntrinsicMatrix(1)/0.8;
IntrinsicMatrix(5) = IntrinsicMatrix(5)/2.1;
How did you obtain those matrix?
img.png
Rod Hid
Rod Hid 2019 年 5 月 11 日
編集済み: Rod Hid 2019 年 5 月 14 日
Those parameters were obtained through the CameraCalibrator app of MATLAB.
Thanks.
With the scale change, the resulting plot looks much more identical to the real object (plot_point_XYZ_1.png), but what is still not fixed is that desviation (plot_point_XYZ_2.png).
P.D: Can a bad calibration generate that deviation?
darova
darova 2019 年 5 月 14 日
honestly, don't know
Rod Hid
Rod Hid 2019 年 5 月 15 日
How did you calculate the divisors that were used in the diagonal elements that respond to the scale?
darova
darova 2019 年 5 月 15 日
I didn't, just intuition
Rod Hid
Rod Hid 2019 年 5 月 17 日
What is the reason of dividing in fx and fy with those values to improve the scale?
darova
darova 2019 年 5 月 17 日
What do you mean? The answer is in your question
Rod Hid
Rod Hid 2019 年 5 月 17 日
What is the relationship between focal length and scale?
darova
darova 2019 年 5 月 17 日
I didn't know those are focal length. Just saw that image and tried to change fx, fy
ProjectionMatrix.jpg

サインインしてコメントする。

回答 (2 件)

Rod Hid
Rod Hid 2019 年 5 月 22 日

0 投票

I made a new calibration of the camera because the pattern presented some problems.
Could you help me find the new values for fx and fy that you calculated earlier for a better proportion of the object?
P.S: Attached the rotation matrix, translation vector, intrinsic matrix and an improved code of the projection matrix of the camera.

1 件のコメント

darova
darova 2019 年 5 月 23 日
I dont' know how to calculate them. Just try different values

サインインしてコメントする。

Rod Hid
Rod Hid 2019 年 6 月 12 日
編集済み: Rod Hid 2019 年 6 月 12 日

0 投票

Is it necessary to remove the distortion from the calibration pattern to calibrate the camera and the captured images to obtain the coordinates of the laser line?

カテゴリ

ヘルプ センター および File ExchangeMATLAB Support Package for USB Webcams についてさらに検索

質問済み:

2019 年 5 月 9 日

編集済み:

2019 年 6 月 12 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by