Ask Your Question
0

projectPoints() Wrong results??

asked 2017-10-02 06:23:27 -0500

mirnyy gravatar image

updated 2017-10-02 06:37:21 -0500

Why is my code snippet giving me weird results for projected points?

//Generate the one 3D Point which i want to project onto 2D plane
vector<Point3d> points_3d;
points_3d.push_back(Point3d(10, 10, 100));
Mat points3d = Mat(points_3d);

//Generate the identity matrix and zero vector for rotation matrix and translation vector
Mat rvec = (Mat_<double>(3, 3) << (1, 0, 0, 0, 1, 0, 0, 0, 1));
Mat tvec = (Mat_<double>(3, 1) << (0, 0, 0));

//Generate a camera intrinsic matrix
Mat K = (Mat_<double>(3,3) 
<< (1000, 0, 50,
    0, 1000, 50,
    0, 0, 1));

//Project the 3D Point onto 2D plane
Mat points_2d;

projectPoints(points_3d, rvec, tvec, K, Mat(), points_2d);

//Output
cout << points_2d;

I get as projected 2D Point
points_2d = (-1.708699427820658e+024, -9.673395654445999e-026)

If i calculate it on a paper on my own, i'm expecting a point points_2d = (150, 150) with that formula: image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-10-02 07:51:18 -0500

LBerger gravatar image

updated 2017-10-02 08:05:50 -0500

because you mustn't use extra parenthesis :

    Mat rvec = (Mat_<double>(3, 3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
    Mat tvec = (Mat_<double>(3, 1) << 0, 0, 0);

    //Generate a camera intrinsic matrix
    Mat K = (Mat_<double>(3, 3)
        << 1000, 0, 50,
            0, 1000, 50,
            0, 0, 1);

With your code in debug there is an exception.

see https://stackoverflow.com/questions/2...

edit flag offensive delete link more

Comments

Ah, thank you! Thank was the problem!

mirnyy gravatar imagemirnyy ( 2017-10-02 08:04:59 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-10-02 06:23:27 -0500

Seen: 216 times

Last updated: Oct 02 '17