# projectPoints() Wrong results??

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: edit retag close merge delete

Sort by » oldest newest most voted

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.

more

Ah, thank you! Thank was the problem!

Official site

GitHub

Wiki

Documentation