calculating Homography matrix from intrinsic and extrinsic camera matrices

124 Views Asked by At

I am working on opencv , halcon. I am trying to implement halcon's gen_image_to_world_plane_map algorithm.

I read some articles about homography martix, and I tried to calculate using intrinsic and extrinsic camera matrices.

Unfortunately, result is wrong.

The Homography

Mat cameraMatrix, distCoeffs; vector<Mat> rvecs, tvecs;
cv::calibrateCamera(objectPoints, imagePoints, img.size(), cameraMatrix, distCoeffs, rvecs, tvecs);

Mat R;
Rodrigues(rvecs[0], R);
Mat T = tvecs[0];

Mat P(3, 4, CV_64F);
R.copyTo(P(cv::Rect(0, 0, 3, 3)));
//T.copyTo(P(cv::Rect(3, 0, 1, 3)));
T.copyTo(P(cv::Rect(2, 0, 1, 3)));

Mat P1 = P.colRange(0, 3);
Mat H = cameraMatrix * P1;
H /= H.at<double>(2, 2);

cv::Mat rectified;
cv::warpPerspective(img, rectified, H, img.size());
0

There are 0 best solutions below