📅 2014-May-09 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ opencv, roi ⬩ 📚 Archive
Many common image operations are performed using Region of Interest in OpenCV. A ROI allows us to operate on a rectangular subset of the image.
The typical series of steps to use ROI is: create a ROI on the image, perform the operation you want on this subregion of the image, reset back the ROI.
Remember that in OpenCV, the origin is the top-left corner of the image. And a ROI is specified using a CvRect
structure.
To copy a cropped region of an image to another image:
// Source image
IplImage* img; // Destination cropped image
IplImage* cropImg; 10, 12, 100, 300); // ROI in source image
CvRect cropRect = cvRect(
cvSetImageROI(img, cropRect);// Copies only crop region
cvCopy(img, cropImg, NULL); cvResetImageROI(img);
To set only a region of an image to a certain value:
IplImage* img;10, 12, 100, 300); // ROI in image
CvRect setRect = cvRect(
cvSetImageROI(img, setRect);255)); // Set region of image to 255
cvSet(img, cvScalar( cvResetImageROI(img);