Ask Your Question
0

Estimation of ball position (3d reconstruction)

asked 2017-06-07 01:56:07 -0600

Marcin gravatar image

updated 2017-06-07 03:43:24 -0600

I have a white small ball in camera view. The ball is in front of camera but higher than camera (Yball > Ycam). View is compensated by undistort(). I try to calculate X and Y position of the ball relative to camera position. What I know:
- know exact distance from the optical center of the camera to the ball,
- know shift dX,dY of my ball in pixels from center of cam view,
- know focal length in pixels (fx and fy from camera matrix determined by camera calibration).

I try calculate physical X and Y position relative to camera using dx,dy,fx,fy,distance. If the position of the ball is near the center of the screen then I can accurately calculate the position using fx and fy. But I noticed, that if the ball is on the side, near the edge of the view (but physicial Y position and distance from camera are the same as previous), then the ball in image is higher. Here's an example:

1) Ball X coordinate is in center


2) Ball X coordinate high (near right side of image)


On the second example, 'top' coordinate changed from 433px to 396px, but ball is on the same physical Y as in previous example and at the same distance from the optical center. So if I use 'fy' (focal length y) to calculate Y position, my estimated position will be different.
Could You please help me, what am I doing wrong? How to calculate the position of the ball, what parameter did not take into account?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-06-07 17:03:14 -0600

Tetragramm gravatar image

Here is sample code to calculate the line of sight vector to a point. Since you know the distance to the ball (the red circle), you can simply scale the line of sight by that distance to get your answer.

Note that this provides the answer in camera coordinates. Where X is to the right, Y is down, and Z is out of the camera. Transform as necessary.

    double x = pt.x;
    double y = pt.y;

    Mat LOS(3,1,CV_64F);

    LOS.at<double>(0) = ptsOut[0].x;
    LOS.at<double>(1) = ptsOut[0].y;
    LOS.at<double>(2) = 1; 

    LOS = cameraMatrix.inv()*LOS;
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-06-07 01:56:07 -0600

Seen: 625 times

Last updated: Jun 07 '17