The function for setting ROI on an image is:
Cvsetimageroi (iplimage* src,cvrect rect); src represents the source image, and rect refers to the ROI region.
If you want to cancel the ROI region, use the function:
Cvresetimageroi (iplimage* src); This function cancels the ROI region on SRC.
Example:
#include <opencv/cv.h> #include <opencv2/highgui/highgui.hpp>using namespace cv;//take a small piece of image from a large image. int main () {/* reads large images */iplimage *IMG1 = cvloadimage ("C:\\users\\liu\\desktop\\a2.bmp",-1); Cvnamedwindow ("Cut", cv_ window_autosize); Cvshowimage ("original", IMG1); /* Set the ROI area of the image note that the ROI area should not be crossed out, must be inside the large image */Cvsetimageroi (IMG1, Cvrect (214, 78,100,100)); /* Allocates memory space for small images cvgetsize (IMG1) returns a cvsize structure that returns the width and height of the image IMG1, since IMG has already set the ROI, so the cvgetsize function is valid for the ROI region, so Returns the width and height of the ROI area */iplimage *img2 = Cvcreateimage (Cvgetsize (IMG1), img1->depth, img1->nchannels); /* Copy the ROI region of IMG1 to img2*/cvcopy (IMG1, Img2, NULL); /* Cancel the ROI area on IMG1 */Cvresetimageroi (IMG1); Cvshowimage ("sub-chart", IMG2); Cvwaitkey (0); Cvreleaseimage (&IMG1); Cvreleaseimage (&IMG2); Cvdestroywindow ("Example1");}
"OpenCV" copy and cut out the ROI area of the image