When we use OPENCV, we sometimes need to trim existing images, such as just a small window of content, so we can get through the area of interest in OPENCV The Interest (ROI) is very easy to implement, the operation is very simple, first build a new iplimage picture, size for you need to cut out the size, and then set up a cvrect variable of that size, to set the ROI of the original image range, and then copy the original image to a new picture , you get what we need, and finally don't forget to restore the ROI of the original image, see the code below:
iplimage *img = Cvloadimage ( " image.jpg , 0 ); Cvrect ROI = cvrect (1 , 1 , 50 , 50 ); Iplimage *newimg = Cvcreateimage (Cvsize (Roi.width, Roi.height), img->depth, Img->nchannels); Cvsetimageroi (IMG, ROI); Cvcopy (Newimg, IMG); Cvresetimageroi (IMG);
OpenCV cut image via ROI crop a picture by interest area