Rotating back points from a rotated image in OpenCV

前端 未结 4 892
攒了一身酷
攒了一身酷 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:21

    If M is the rotation matrix you get from cv::getRotationMatrix2D, to rotate a cv::Point p with this matrix you can do this:

    cv::Point result;
    result.x = M.at(0,0)*p.x + M.at(0,1)*p.y + M.at(0,2);
    result.y = M.at(1,0)*p.x + M.at(1,1)*p.y + M.at(1,2);
    

    If you want to rotate a point back, generate the inverse matrix of M or use cv::getRotationMatrix2D(center, -rotateAngle, scale) to generate a matrix for reverse rotation.

提交回复
热议问题