Take the 2-minute tour ×
Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. It's 100% free, no registration required.

I have a camera and its K matrix (calibration matrix) also I have image of plane, I know the real points of the 4 corners and thier correspondence pixel. I know how to compute the H matrix if z=0 (H is homography matrix between Image and the real plane). And Now I try to get the real point of the plane (3D point) with the rotation matrix and the transltion vector I follow this paper :Calibrating an Overhead Video Camera by Raul Rojas in section 3 - 3.3. My code is:

ImagePointsScreen=[16,8,1;505,55,1;505,248,1;44,301,1;];

screenImage=imread( 'screen.jpg');
RealPointsMirror=[0,0,1;9,0,1;9,6,1;0,6,1]; %Mirror
RealPointsScreen=[0,0,1;47.5,0,1;47.5,20,1;0,20,1];%Screen
imagesc(screenImage);
hold on
for i=1:4
    drawBubble(ImagePointsScreen(i,1),ImagePointsScreen(i,2),1,'g',int2str(i),'r')
end

Points3DScreen=Get3DpointSurface(RealPointsScreen,ImagePointsScreen,'Screen');

figure
hold on
plot3(Points3DScreen(:,1),Points3DScreen(:,2),Points3DScreen(:,3));
for i=1:4
    drawBubble(Points3DScreen(i,1),Points3DScreen(i,2),1,'g',int2str(i),'r')
end



function [ Points3D ] = Get3DpointSurface( RealPoints,ImagePoints,name)
M=zeros(8,9);

for i=1:4

M((i*2)-1,1:3)=-RealPoints(i,:);
M((i*2)-1,7:9)=RealPoints(i,:)*ImagePoints(i,1);
M(i*2,4:6)=-RealPoints(i,:);
M(i*2,7:9)=RealPoints(i,:)*ImagePoints(i,2);   

end

[U S V] = svd(M);
X = V(:,end);
H(1,:)=X(1:3,1)';
H(2,:)=X(4:6,1)';
H(3,:)=X(7:9,1)';
K=[680.561906875074,0,360.536967117290;0,682.250270165388,249.568615725655;0,0,1;];

newRO=pinv(K)*H;
h1=newRO(1:3,1);
h2=newRO(1:3,2);

scaleFactor=(norm(h1)+norm(h2))/2;
newRO=newRO./scaleFactor;
r1=newRO(1:3,1);
r2=newRO(1:3,2);
r3=cross(r1,r2);
r3=r3/norm(r3);

R=[r1,r2,r3];

RInv=pinv(R);
O=-RInv*newRO(1:3,3);
M=K*[R,-R*O];
for i=1:4
   res=pinv(M)* [ImagePoints(i,1),ImagePoints(i,2),1]';
   res=res';
   res=res*(1/res(1,4));
   Points3D(i,:)=res';

end
Points3D(i+1,:)=Points3D(1,:);  %just add the first point to the end of the array for draw square

end



function drawBubble (xcenter, ycenter, radius, color, string,colorNum)
% draw circle with input xcenter, ycenter, radius, color and text
angles = linspace(0, 2*pi, 40);
bubx = xcenter + (radius * cos(angles));
buby = ycenter + (radius * sin(angles));
fill(bubx, buby, color, 'EdgeColor', color)
text(xcenter, ycenter, string, 'Color', colorNum, 'FontSize', 13, ...
       'FontWeight', 'normal', 'HorizontalAlignment', 'center')

end

My problem is that I don't get good results

1.The point 1 is at (0,0,0) and this is not the real location

2.the points are upside down

What I am doing worng?

share|improve this question
    
you should put H = reshape(V(:,end),3,3)'; in what way is the points upsidedown? there are a couple of different ways. –  SlimJim Oct 29 '12 at 8:44
    
see if you can find the samething in this document: www.nada.kth.se/~stefanc/gc_lec_notes.pdf –  SlimJim Oct 29 '12 at 8:46
    
Can you provide a full code, including the subroutines? –  Andrey Oct 29 '12 at 9:00
    
SlimJim I can't upload Image, you can see the result here : stackoverflow.com/questions/12133366/… –  Beno Oct 29 '12 at 16:23
    
Andrey I think now it all the code here –  Beno Oct 29 '12 at 18:19
show 1 more comment

2 Answers 2

up vote 1 down vote accepted

I found the answer in the paper: Calibrating an Overhead Video Camera by Raul Rojas in section 3 - 3.3.

for the start: H=K^-1*H

1) Given four points in the image and their known coordinates in the world, the matrix H can be recovered, up to a scaling factor . We know that the first two columns of the rotation matrix R must be the first two columns of the transformation matrix. Let us denote by h1, h2, and h3 the three columns of the matrix H.

2) Due to the scaling factor we then have that xr1 = h1 and xr2 = h2 Since |r1| = 1, then

x = |h1|/|r1| = |h1| and

x = |h2|/|r2| = |h2|.

3) We can thus compute the factor and eliminate it from the recovered matrix H. We just set

H'= H/x

4) In this way we recover the first two columns of the rotation matrix R. The third column of R can be found remembering that any column in a rotation matrix is the cross product of the other two columns (times the appropriate plus or minus sign). In particular

r3 = r1 × r2

5) Therefore, we can recover from H the rotation matrix R. We can also recover the translation vector (the position of the camera in field coordinates). Just remember that

h'3 = −R^t

6) Therefore the position vector of the camera pin-hole t is given by

t = −R^-1 h3

share|improve this answer
add comment

Solving the upside down part is quite easy, just reverse the y coordinates, for instance:

y = max(y) - y

Then there is the point of the incorrect position, assuming you know or can finde the coordinates of point 1 in both pictures, say: Xorig Yorig Xnew Ynew

You can just shift the entire image by adding Xorig-Xnew to all x coordinates, and Yorig-Ynew to all y coordinates

share|improve this answer
    
Thanks,I did not mean to change the image. I am looking for formula that do it automaticly. I have some bug in my formula and I am looking to solve it and not to bypass the problem –  Beno Nov 20 '12 at 12:23
    
In that case the only solution would be to run the code line by line, and see untill what point the variables are what you expect them to be. The moment when this changes you know what to adjust. –  Dennis Jaheruddin Nov 20 '12 at 12:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.