# Convert pixel position to world direction?

I have calibrated my camera with a checkerboard and achieved the distortion parameters and Intrinsic matrix of my camera.

Using these I have estimated the camera position and orientation using solvePnP against a known known set of reference points.

Now I want to find the world direction, from the camera toward a blob I am detecting inside my image. So I want to convert a pixel position to a 3D vector in that direction.

I want the direction so I can determine where in the world a ball is located. I have two cameras. If both of them can see the blob I will find the point nearest both lines and if only one can observe the ball I will just use the directions crossing with a the ground plane.

I am using blob detection in HSV colorspace to find the ball.

Any ideas on how to continue?

Kind regards

Jesper

edit retag close merge delete

Sort by » oldest newest most voted

If you have the ball position at (x,y) (after correcting the distortion), you can just write the projection equations:

x_px = f_x * X/Z + c_x
y_px = f_y * Y/Z + c_x


Where (X,Y,Z) are possible 3d coordinates in the world. As you have only two equations for three unknowns (X,Y,Z), this will give you the possible positions of the ball along a line. This line goes through the optical center of your camera and e.g. the point [(x_px-c_x)/f_x,(y_px-c_y)/f_y,1]. As you have the 6D transformation between both cameras, you can bring the two rays into one coordinate system and find a point with minimal distance to both of them. (don't try to intersect them, as they probably never have an intersection point)

more

You could use cv::triangulatePoints().

more

Official site

GitHub

Wiki

Documentation