0

I extracted parts of an image using the cv::Rect

Mat myimg = imread("gopro.png");
Mat draw = Mat(myimg.size(), myimg.type(), Scalar::all(0));
Rect r2 = Rect(417, 144, 153, 85);
myimg(r2).copyTo(draw(r2));

It copies the rectangle just fine. My question is : is there a way to rotate that rectangle before copying it to the other Mat ?

I ve already tried cv::RotatedRect, but it s not what i am searching for. Or maybe I didn't know how to use it.

If anyone has an idea how to do so, please help.

  • 1
    "rotate the output of cv::Rect" makes very little sense. [`cv::Rect`](https://docs.opencv.org/3.1.0/d2/d44/classcv_1_1Rect__.html) is a class representing the mathematical concept of an axis-aligned 2D rectangle, defined by the coordinates of its top-left corner along with width and height. As such it has no "output" -- some of it's member functions may, but you don't use any. What you are actually using is [`cv::Mat::operator()`](https://docs.opencv.org/3.1.0/d3/d63/classcv_1_1Mat.html#a07413f2e3e63a12185b8b218c24c7270), using a `Rect` to specify the ROI to extract. The result is again `Mat`. – Dan Mašek Apr 25 '18 at 22:55
  • 1
    So, after extracting it, you want to [rotate](https://stackoverflow.com/questions/22041699/rotate-an-image-without-cropping-in-opencv-in-c) the ROI after you extracted it, then copy it to the target. If the rotation is not multiple of 90 degrees, you most likely want to create a binary mask matching the original ROI, rotate that the same amount, and use it with `copyTo` to copy only the desired area. – Dan Mašek Apr 25 '18 at 23:00
  • 1
    I tried your approach and it worked, thank you – Sara Ahsain Apr 29 '18 at 13:44

0 Answers0