OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 20 Mar 2014 13:34:37 -0500How to calculate the position of the camera from an imagehttp://answers.opencv.org/question/30326/how-to-calculate-the-position-of-the-camera-from-an-image/I have four traingles placed on the corners of an A0 page. Using openCV I have been able to calibrate the camera, through that i have got the distortion and intrinsic files saved. I have been able to detect the triangles using cvblobs or could do it using contours. But what I have to do now is to find the position of the camera so that I could figure out the ideal position to recognize the triangles. I don't know how to do the calculation and to code it. If anyone could please provide the steps in how to carry out and possibly example codes in c++, it would be great.
Thank you in advance.Thu, 20 Mar 2014 09:52:54 -0500http://answers.opencv.org/question/30326/how-to-calculate-the-position-of-the-camera-from-an-image/Answer by FraserT for <p>I have four traingles placed on the corners of an A0 page. Using openCV I have been able to calibrate the camera, through that i have got the distortion and intrinsic files saved. I have been able to detect the triangles using cvblobs or could do it using contours. But what I have to do now is to find the position of the camera so that I could figure out the ideal position to recognize the triangles. I don't know how to do the calculation and to code it. If anyone could please provide the steps in how to carry out and possibly example codes in c++, it would be great. </p>
<p>Thank you in advance.</p>
http://answers.opencv.org/question/30326/how-to-calculate-the-position-of-the-camera-from-an-image/?answer=30335#post-id-30335Look into the function [solvePnP](http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#solvepnp) which calculates the cameras perspective from given points, so long as you know the model space positions of these points. I assume since they are in the corners of a sheet of paper, you know the real world positions of the triangles?
With 4 points, you could use the P3P flag to solve for 3 points.
The process is very similar to obtaining the camera position relative to an Augmented Reality marker, so looking up tutorials/demo's of that would be a good start. Thu, 20 Mar 2014 13:34:37 -0500http://answers.opencv.org/question/30326/how-to-calculate-the-position-of-the-camera-from-an-image/?answer=30335#post-id-30335