confuse about projectPoints

asked 2016-02-04 01:58:04 -0600

mm71 gravatar image

I'm trying to get projection points using projectPoints function. But the output is not correct. I probably using the function wrong or did mistake somewhere, but I'm not sure where. This is my code

cv::Mat r(3, 3, cv::DataType<float>::type);
cv::Mat rR(1, 3, cv::DataType<float>::type);
cv::Mat c(3, 3, cv::DataType<float>::type);
std::vector<cv::Point2f> projectedPoints;
std::vector<cv::Vec3f> objectPoints;


r.at<float>(0, 0) = 1;
r.at<float>(1, 0) = 0;
r.at<float>(2, 0) = 0;

r.at<float>(0, 1) = 0;
r.at<float>(1, 1) = 1;
r.at<float>(2, 1) = 0;

r.at<float>(0, 2) = 0;
r.at<float>(1, 2) = 0;
r.at<float>(2, 2) = 1;

c.at<float>(0, 0) = -500;
c.at<float>(1, 0) = 0;
c.at<float>(2, 0) = 0;

c.at<float>(0, 1) = 0;
c.at<float>(1, 1) = -500;
c.at<float>(2, 1) = 0;

c.at<float>(0, 2) = 320;
c.at<float>(1, 2) = 240;
c.at<float>(2, 2) = 1;

objectPoints.push_back(cv::Point3f(150, 200, 350));

cv::Rodrigues(r, rR);


cv::Mat T(1, 3, cv::DataType<float>::type);
T.at<float>(0, 0) = -50;
T.at<float>(1, 0) = -85;
T.at<float>(2, 0) = -110;


// Create zero distortion
cv::Mat distCoeffs(4, 1, cv::DataType<float>::type);
distCoeffs.at<float>(0) = 0;
distCoeffs.at<float>(1) = 0;
distCoeffs.at<float>(2) = 0;
distCoeffs.at<float>(3) = 0;

cv::projectPoints(objectPoints, rR, T, c, distCoeffs, projectedPoints);

I appreciate much if anyone could point out the mistake.

edit retag flag offensive close merge delete