Opencv _ copy one or more ROI image regions

Source: Internet
Author: User


During image processing, we often need to process one or more areas of interest in the image. In opencv, we can easily obtain sub-images in the specified ROI Area. The following code demonstrates how to obtain a single ROI or multiple ROI image regions.


// Copy one or more ROI image regions // Author: www.icvpr.com // blog: http://blog.csdn.net/icvpr # include <iostream> # include <vector> # include <opencv2/opencv. HPP> int main () {CV: mat srcimage = CV: imread (".. /test.jpg "); // save an ROI image region CV: mat roiimage; CV: rect (100,100,100,100); srcimage (rect ). copyto (roiimage); CV: imshow ("ROI", roiimage); CV: imwrite ("roi.jpg", roiimage); CV: waitkey (0 ); // save multiple ROI image regions STD: vector <CV: rect> rects; For (size_t I = 0; I <4; I ++) {rects. push_back (CV: rect (I * 10, I * 10, 50, 50);} STD: vector <CV: mat> subimages; for (INT I = 0; I <rects. size (); I ++) {CV: mat tempimg; srcimage (rects [I]). copyto (tempimg); subimages. push_back (tempimg); CV: imwrite ("roi.jpg", subimages [I]); CV: imshow ("subimage", subimages [I]); CV :: waitkey (0);} return 0 ;}

Source image

Single ROI image region

Multiple ROI image regions

Related content: www.icvpr.com

-------------------------------------------------------
<Reprint Please note: http://blog.csdn.net/icvpr>

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.