简体   繁体   中英

Coordinate transform from ROI in original image

I have a little problem with some projection and geometry. I have an image where I detect a square. After the square detection, I crop the square from image. In the ROI I detect the point P(x,y) (see the image below).

在此处输入图片说明

My problem is that I know the coordinate of point P in the ROI, the coordinates of A,B,C,D, and rotation of ROI (RotatedRect::angle) but I want to get the coordinate of P in original image. Any advice could help.

For ROI crop I have this code

vector< RotatedRect > rect(squares.size());

for (int i=0;i<squares.size();i++) 
{
    rect[i] = minAreaRect(Mat(squares[i]));
    Mat M,rotated,cropped;
    float angle = rect[i].angle;
    Size rect_size = rect[i].size;

    if (rect[i].angle<-45)
    {
        angle += 90;
        swap(rect_size.width,rect_size.height);
    }

    M = getRotationMatrix2D(rect[i].center,angle,1.0);
    warpAffine(cameraFeed,rotated,M,cameraFeed.size(),INTER_CUBIC);
    getRectSubPix(rotated,rect_size,rect[i].center,cropped);
    cropped.copyTo(SatelliteClass[i].m_matROIcropped);
    SatelliteClass[i].m_vecRect = rect[i];
}

It's basically a question of vector addition. Take the inverse of M, apply it to P ( so you're rotating P back to the original frame ) and then add P to the left corner of the rectangle.

There might be a way to do this within the API you're using instead of reinventing the wheel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM