Ask Your Question
0

Trying to re-distort image points using projectPoints

asked 2016-07-25 04:06:53 -0600

Allan Nørgaard gravatar image

Knowing things about a video-feed from a GoPro camera, I would like to draw on top of the image, which in terms requires me to go from undistorted to distorted image points.

I've tried to use projectPoints, since the documentation states this should suffice, but the results doesn't look correct to me. The following is what I'm trying:

Vec<float,8> d = Vec<float,8>(k1, k2, p1, p2, k3, k4, k5, k6);
            [1740    0 1919.5]
intrinsic = [   0 1745 1079.5]  (3x3 float matrix)
            [   0    0    1  ]

My function takes an undistorted image-point, undistorted, converts into a 1x3 matrix, and i expect an 1x2 matrix containing the distorted point in return.

Mat dmat = Mat_<float>(1,3);
Mat umat = (Mat_<float>(1,3) << undistorted.x, undistorted.y, 1.0);
projectPoints(umat, Vec3f(0,0,0), Vec3f(0,0,0), intr, d, dmat);

A sample input might be Point2f(1920,315), returning [-6.15e+6, -1.86e+6] while manually calculating the distorted point gives me [1919.93, 257.136] which seems more likely.

I am suspecting projectPoints not to play well with my intrinsic matrix, should it (and image points) be normalized first?

Any hints on what might be wrong?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2016-07-25 17:46:08 -0600

Tetragramm gravatar image

It has to do with how you are creating the points. The projectPoints function doesn't remove the camera matrix and put it back like undistortPoints does, it just puts it back in. You have to normalize your points by the camera matrix manually.

Just replace dist::cameraMatrix and dist::distortion with your variables.

std::vector<Point3f> in;
std::vector<Point2f> out, out2;
std::cout << "[" << 512 << ", " << 200 << ", 1]\n\n";
in.push_back(Point3f((512-dist::cameraMatrix.at<double>(0,2))/dist::cameraMatrix.at<double>(0,0), (200 - dist::cameraMatrix.at<double>(1, 2))/ dist::cameraMatrix.at<double>(1,1), 1));

std::cout << in[0] << "\n\n";

projectPoints(in, Mat::zeros(3, 1, CV_64FC1), Mat::zeros(3, 1, CV_64FC1), dist::cameraMatrix,
    dist::distortion, out);

undistortPoints(out, out2, dist::cameraMatrix, dist::distortion, noArray(), dist::cameraMatrix);

std::cout << out[0] << "\n\n";

std::cout << out2[0] << "\n\n";
edit flag offensive delete link more

Comments

@Tetragramm do you think this might be related to the problem I have here? https://answers.opencv.org/question/2...

trigal gravatar imagetrigal ( 2020-07-02 13:37:40 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-25 04:06:53 -0600

Seen: 3,271 times

Last updated: Jul 25 '16