Rotating back points from a rotated image in OpenCV

前端 未结 4 942
攒了一身酷
攒了一身酷 2020-12-17 16:43

I’m having troubles with rotation. What I want to do is this:

  • Rotate an image
  • Detect features on the rotated image (points)
  • Rotate back the p
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-17 17:15

    For a rotation matrix, its transpose is its inverse. So you can just do M.t() * r to move it back to your original frame, where r is a cv::Mat (you might have to convert it to a cv::Mat from a cv::Point2f or whatever, or just write out the matrix multiplication explicitly).

    Here's the code to do it explicitly (should be correct, but warning, it's entirely untested):

    cv::Point2f p;
    p.x = M.at(0, 0) * r.x + M.at(1, 0) * r.y;
    p.y = M.at(0, 1) * r.x + M.at(1, 1) * r.y;
    // p contains r rotated back to the original frame.
    

提交回复
热议问题