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>