Skip to content

Instantly share code, notes, and snippets.

@ericosur
Last active March 8, 2021 09:05
Show Gist options
  • Save ericosur/f11d74707f91df5a18b524fff203a698 to your computer and use it in GitHub Desktop.
Save ericosur/f11d74707f91df5a18b524fff203a698 to your computer and use it in GitHub Desktop.
opencv crop ROI of an image
// You mention that you start with a CVMat* imagesource
CVMat * imagesource;
// Transform it into the C++ cv::Mat format
cv::Mat image(imagesource);
// Setup a rectangle to define your region of interest
cv::Rect myROI(10, 10, 100, 100);
// Crop the full image to that image contained by the rectangle myROI
// Note that this doesn't copy the data
cv::Mat croppedImage = image(myROI);
// from: https://stackoverflow.com/questions/8267191/how-to-crop-a-cvmat-in-opencv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment