Assuming you already have the coordinates of your ROI, you can crop your cv::Mat
like this:
// your source image
cv::Mat image(imagesource);
// a rectangle with your ROI coordinates
cv::Rect myROI(10, 10, 100, 100);
// a "reference" to the image data within the rectangle
cv::Mat croppedImage = image(myROI);
Note that this does not copy the image data. Both, image
and croppedImage
share the same underlying raw data (a detailed example can be found in the opencv documentation). When you're done with the big source image, you can do image.release()
and croppedImage = croppedImage.clone();
to deallocate all unnecessary data (outside of your ROI).
EDIT:
I didn't work with AL::ALImage::ROI
yet, but the definition in alimage/alimage.h looks familiar to cv::Rect
. So you can probably do the following:
// let's pretend you already got your image ...
AL::ALImage yourImage;
// ... and a ROI ...
AL::ALImage::ROI yourROI;
// ... as well as a Mat header with the dimensions and type of yourImage
cv::Mat header;
// then you can convert the ROI, ...
cv::Rect cvROI(yourROI.x, yourROI.y, yourROI.w, yourROI.h);
// ... wrap ALImage to a Mat (which should not copy anything) ...
header.data = yourImage.getData();
// ... and then proceed with the steps mentioned above to crop your Mat
cv::Mat cropped = header(cvROI);
header.release();
cropped = cropped.clone();
// ...
// your image processing using cropped
// ...
I hope this helps.