Search code examples
opencvroi

get Original image from ROI image in opencv


is it possible to get back original image from image ROI? for example say we have

cv::Mat image = imread("image.jpg", 0);
cv::Mat imageROI = image(0, 0, 100, 100);
myFunction(imageROI);

and in myFunction I want to work with original image. is there any way to convert imageROI to original image when we don't access the original image?


Solution

  • Just incase anybody looks at this question you can actually do this

    cv::Mat mat = ...
    
    cv::Size  size;
    cv::Point offset;
    // find original image size, and get offset of roi
    mat.locateROI(size, offset);
    // put image back to original size;
    mat.adjustROI(offset.y, size.height - mat.rows, offset.x, size.width- mat.cols);