Coordinate transform from ROI in original image

asked 2016-03-09 06:12:28 -0600

Graver gravatar image

updated 2016-03-09 07:01:27 -0600

Hello!

I have a little problem with som 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).

image description

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.

Thanks!

EDIT :

For ROI crop I have this code

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

for (int i=0;i<squares.size();i++) // square.size() is the number of detected square(in some cases could be more squares in original image)
{
    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];
}
edit retag flag offensive close merge delete

Comments

It seems simple... What have you tried so far?

strann gravatar imagestrann ( 2016-03-09 06:51:38 -0600 )edit

Yes is simple. My problem is that I can't get the offset of the ROI because my ROI was created with RotatedRect. When i try to use locateROI it doesn't gave me the offset. After i get the offset i will make the rotation of points with the angle of RotatedRect "see the code".

Graver gravatar imageGraver ( 2016-03-09 07:07:35 -0600 )edit