OpenCV + photogrammetry

V1t picture V1t · May 5, 2011 · Viewed 8.3k times · Source

i have a stereopair, photo 1: http://savepic.org/1671682.jpg photo 2: http://savepic.org/1667586.jpg

there is coordinate system in each image. How can I find coordinates of point A in this system using OpenCV library. It would be nice to see sample code. I've looked for it at opencv.willowgarage.com/documentation/cpp/camera_calibration_and_3d_reconstruction.html but haven't found (or haven't understood :) )

Answer

TimZaman picture TimZaman · Mar 4, 2015

Your 'stereo' images are fine. What you have already done is solve the correspondence problem: in both images you have indicated points 'A'. This means that you know which pixel corresponds to eachother labeling point 'A'.

What you want to do, is triangulate where your camera is. You can only do this by first calibrating your camera. This is inside of OpenCV already. http://docs.opencv.org/doc/tutorials/calib3d/camera_calibration/camera_calibration.html http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html

This gives you the exact vector/ray of light for each vector, and the optical center of your cameras through which the ray passes. Moreover, you need stereo calibration. This establishes the orientation and position of each camera with respect through each other.

From that point on, your triangulation is simple, knowing the pixel location in both images of point 'A'. You have

  • Location and orientation of camera 1 and camera 2
  • Otical Ray Vector (pixel location) from the cameras to label 'A'.

So you have 2 locations in space, and 2 rays from these location. The intersection of these rays is your 3D answer.

Note that in practice there rays will never exactly intersect (2 lines in 3D rarely do), so you need to approximate. Use opencv function triangulatePoints(), using the input of the stereo calibration and the pixel index relating to label A.