OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Tue, 24 Jul 2018 20:49:42 -0500Convert pixel position to world direction?http://answers.opencv.org/question/66047/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
Sat, 11 Jul 2015 10:25:21 -0500http://answers.opencv.org/question/66047/convert-pixel-position-to-world-direction/Answer by mannyglover for <p>I have calibrated my camera with a checkerboard and achieved the distortion parameters and Intrinsic matrix of my camera.</p>
<p>Using these I have estimated the camera position and orientation using solvePnP against a known known set of reference points. </p>
<p>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.</p>
<p>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.</p>
<p>I am using blob detection in HSV colorspace to find the ball. </p>
<p>Any ideas on how to continue?</p>
<p>Kind regards</p>
<p>Jesper</p>
http://answers.opencv.org/question/66047/convert-pixel-position-to-world-direction/?answer=196325#post-id-196325You could use cv::triangulatePoints().Tue, 24 Jul 2018 20:49:42 -0500http://answers.opencv.org/question/66047/convert-pixel-position-to-world-direction/?answer=196325#post-id-196325Answer by FooBar for <p>I have calibrated my camera with a checkerboard and achieved the distortion parameters and Intrinsic matrix of my camera.</p>
<p>Using these I have estimated the camera position and orientation using solvePnP against a known known set of reference points. </p>
<p>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.</p>
<p>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.</p>
<p>I am using blob detection in HSV colorspace to find the ball. </p>
<p>Any ideas on how to continue?</p>
<p>Kind regards</p>
<p>Jesper</p>
http://answers.opencv.org/question/66047/convert-pixel-position-to-world-direction/?answer=66048#post-id-66048If 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)
Sat, 11 Jul 2015 11:16:32 -0500http://answers.opencv.org/question/66047/convert-pixel-position-to-world-direction/?answer=66048#post-id-66048