I’m interested in knowing the position of the camera with respect to a known object (calibration object). This is of interest because I can normalize lots of pictures taken of the same place. I can normalize them in such a way that the camera position would be similar (to a certain degree) in all of them. Also, fiddling with opencv is, up until now, cool :)
At the moment I finished the first phase of this mini-project. I have managed to calculate the extrinsic camera values from my laptop webcam and I can calculate the extrinsic values of a known object, specifically a chessboard printout, moving around in front on the webcam. After calculating the intrinsic values, which I don’t care much about, the algorithm outputs the extrinsic values to stdout. I can see that movements in pitch, roll and yaw are consistently output to my shell. I can also see the three directional movements in the three directional axis.
I used opencvs chessboard detection algorithms and its solvePnP and calibrateCamera functions. The command accepts a list of images or a stream from a camera. I prefer to use a camera stream for testing, but the final objective is to use it with list of images. The gist of the process goes something like this:
- Calibrate camera (get intrinsic values): The algorithm detects some points in the chessboard image and relates them to the “real” object points. By using these two sets of information, the algorithm can calculate the camera distortion information and the camera matrix information . The calibration takes 20 images/frames.
- Even though I get intrinsic values after the camera calibration, I am only interested in the extrinsic values. So I use the found intrinsics and pass them to solvePnP to get only the extrinsic values.
- I output each extrinsic I find.
My next move is to use the re-projection error to improve the intrinsic values calculation. Hopefully that will increase the accuracy of the calculated extrinsic values. I also want to put my code in some kind of git repository so I can keep track of it better.
The following were links that helped me find my way through the math and the coding:http://www.vision.caltech.edu/bouguetj/calib_doc/ (It has matlab code and an extensive explanation of what is happening under the covers.) http://www.youtube.com/watch?v=DrXIQfQHFv0 (Cool video that shows what can be done with the extrinsic parameters) http://www.amazon.co.uk/Learning-OpenCV-Computer-Vision-Library/dp/0596516134/ (chapter 11, on camera models and calibration. Very good explanation and more code goodies )
I’ll put my code on my ITU page for now (until I get something better in the research group server, or until I put it in github), Comments and patches are greatly appreciated :http://www.itu.dk/people/jogr/opencv/imageadjust.tar.gz  http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/EPSRC_SSAZ/node3.html  http://opencv.willowgarage.com/documentation/camera_calibration_and_3d_reconstruction.html#calibratecamera2  http://opencv.willowgarage.com/documentation/cpp/camera_calibration_and_3d_reconstruction.html#cv-solvepnp