Ask Your Question
0

cv::remap on a pre-rotated image

asked 2018-11-20 14:09:29 -0500

logidelic gravatar image

updated 2018-11-20 14:10:54 -0500

cv::remap on a pre-rotated image

I am undistorting images from my camera, based on calibration data, using code such as this:

cv::fisheye::estimateNewCameraMatrixForUndistortRectify(cameraMatrix, calibCoeffs, imgSize, cv::Matx33d::eye(), newCamMat, 1);

cv::fisheye::initUndistortRectifyMap(cameraMatrix, calibCoeffs, cv::Matx33d::eye(), newCamMat, imgSize, CV_16SC2, map1, map2);

cv::remap(imgSrc, imgDst, map1, map2, cv::INTER_LINEAR);

Works great. However, I would like to use a hardware feature of my camera to allow image rotation by 90 degrees. For example, if the original image (for which the undistortion works) is 1920x1080, then I would also like to apply the undistortion to rotated frames from the camera (1080x1920).

I (very naively) tried to simply rotate the transformation matrix before using it on the rotated frames, as in:

cv::rotate(map1, map1, cv::ROTATE_90_CLOCKWISE);
cv::rotate(map2, map2, cv::ROTATE_90_CLOCKWISE);
cv::remap(imgSrc, imgDst, map1, map2, cv::INTER_LINEAR);

But this did not provide the expected results.

(Obviously one approach would be to do the rotation after (or along with) the undistortion, but I'd like to avoid that if possible for performance reasons; currently it is being done by the hardware).

Any pointers in the right direction would be appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-11-20 16:17:30 -0500

Several input parameters to the OpenCV calls you are making will need to be modified so that they apply the the reoriented (rotated 90 degrees) input image: cameraMatrix (K), calibCoeffs (D), and imgSize must be modified to apply to the new image orientation.

See https://docs.opencv.org/master/dc/dbb... for a starting point of resources to look into.

  • K is simple, exchange fx with fy, and cx with cy.
  • D is more complicated - the p1, p2, and p3 coefficients are affected by rotation (I don't have a ready answer on those).
  • imgSize must of course be changed to match the new number of rows and columns.
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-11-20 14:09:29 -0500

Seen: 122 times

Last updated: Nov 20 '18