"OpenCV" copy and cut out the ROI area of the image

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.