OpenCV Mat copyTo, Clone, ROI example code


OpenCV Mat copyTo, Clone, ROI example code

...
Mat img = imread("ss.jpg");
 
 Rect r(img.cols / 4, img.rows / 4, img.cols / 4 * 2, img.rows / 4 * 2);

 //clone #1
 Mat img2 = img.clone();
 bitwise_not(img2, img2);

 //clone #2
 Mat img5 = img(r).clone();


 //copyTo #1
 Mat cimg;
 img.copyTo(cimg);

 //copyTo #2
 Mat cimg2;
 img(r).copyTo(cimg2);

 //copyTo #3
 Mat cimg3( Size(img.cols*2, img.rows), img.type() );
 cimg3.setTo(255);
 img.copyTo(cimg3(Range::all(), Range(0, img.cols)));
 img2.copyTo(cimg3(Range::all(), Range(img2.cols, img2.cols * 2)));

 //set roi
 Mat roi(img, r);
 //invert color
 bitwise_not(roi, roi);


 namedWindow("img2", 0); //make window
 imshow("img2", cimg); //show
 namedWindow("img3", 0); //make window
 imshow("img3", cimg2); //show
 namedWindow("img4", 0); //make window
 imshow("img4", cimg3); //show
 namedWindow("img5", 0); //make window
 imshow("img5", img5); //show
 namedWindow("img", 0); //make window
 imshow("img", img); //show
 
 waitKey(0);

...



Comments

Popular posts from this blog

OpenCV Stitching example (Stitcher class, Panorama)

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Real-time N camera stitching Class.

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Optical Flow sample source code using OpenCV

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

yuv422(YUYV) to RGB and RGB to yuv422(YUYV), (Using OpenCV and TBB)

(C, C++) TinyXML , xml read & write

(OpenCV Study) calcOpticalFlowFarneback example source code ( dense optical flow )