0

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());
Markus
  • 5,976
  • 5
  • 6
  • 21
Ershat
  • 29
  • 4
  • related: https://stackoverflow.com/questions/77013663/implement-halcons-gen-image-to-world-plane-map-in-opencv – Christoph Rackwitz Sep 01 '23 at 08:29
  • 1
    extrinsics matrix must be 3x4, not 3x3. -- you need to be clear on the difference between points in 3D, and points on an image plane. a homography maps 2D to 2D. an extrinsics matrix maps 3D to 3D. a projection matrix maps 3D to 2D. you are missing the "2D to 3D" part. that sounds impossible but isn't because it's only a factor in a final matrix that maps 2D to 2D. – Christoph Rackwitz Sep 01 '23 at 08:31
  • @Christoph Rackwitz thanks, I got the difference. is there Any idea about how to rectify image that captured with rotations and translations? I tried findHomograpy and it worked. but I don't think this is a good idea. I read halcon's `gen_image_to_world_plane_map` documentation and could not found any usefull pieces for me yet. and the algorithm does not take neither points sets or calibration id. – Ershat Sep 01 '23 at 22:28

0 Answers0