How can exchange "ginput" image data units to world units(mm)?
5 views (last 30 days)
Show older comments
Hi everyone;
I want to measure the distance in mm so i use tform and invtform matrix to exchange the image and world data units. However, i have this error after running my code. Here is the code:
PS: First i calibrate my camera and then i run these codes...
a=imread('calib8.jpg');
>> im = undistortImage(a, cameraParameters);
>> figure; imshow(im);
>> [x,y] = ginput(2)
>> [imagePoints, boardSize] = detectCheckerboardPoints(im);
>> Ainv=inv(cameraParameters.IntrinsicMatrix);
>> squareSize=9;
>> worldPoints = generateCheckerboardPoints(boardSize, squareSize);
>> H=fitgeotrans(worldPoints, imagePoints, 'projective');
>> H=H.T;
>> h1=H(1,:);
>> h2=H(2,:);
>> h3=H(3,:);
>> lambda=1/norm(h1*Ainv);
>> r1=lambda*h1*Ainv;
>> r2=lambda*h2*Ainv;
>> r3=cross(r1,r2);
>> R=[r1; r2; r3];
>> [U,~,V]=svd(R);
>> R=U*V';
>> t= lambda*h3*Ainv
t =
-18.7109 11.7857 150.6906
>> T = [R(1, :); R(2, :); t] * cameraParameters.IntrinsicMatrix;
>> tform = projective2d(T);
>> imagePoints1=[x;y]
imagePoints1 =
106.0000
104.0000
132.0000
55.0000
>> worldPoints1 = transformPointsInverse(tform, imagePoints1);
Error using projective2d/transformPointsInverse (line 189)
transformPointsInverse requires that X is an Nx2 matrix.
0 Comments
Accepted Answer
Dima Lisin
on 1 May 2014
Instead of a semicolon in
imagePoints1=[x;y]
use a comma:
imagePoints1=[x, y]
This will create an two-column matrix instead of a one-column vector.
0 Comments
More Answers (0)
See Also
Categories
Find more on Point Cloud Processing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!