Whether in the picture display or in the process of finding corners in the optical flow method, we all encounter the ROI thing. Its role is to allow us to focus on the image or an area of the current video frame (which we call an area of interest) instead of processing the entire image or the entire video frame, not only eliminating unnecessary error disturbances, but also reducing the amount of computation. Next, describe how to set ROI in image and optical flow video.
Image set ROI
The code is as follows:
/** description:setting ROI in image * author:liulongpo* date:2015 March 8 19:50:26**/#include <cv.h>#include using namespace STD;intMain (intargcChar**ARGV) {//Load Original imageiplimage* img = cvloadimage ("F://12.jpg");//Create a new image to display the area of interestiplimage* Img2 = cvcreateimage (Cvgetsize (IMG), ipl_depth_8u,3);//Create a rectangular area of interest ROICvrect rect = Cvrect ( -, -, -, -); Cvcopy (IMG,IMG2); Cvsetimageroi (Img2,rect); Cvnamedwindow ("source image",1); Cvshowimage ("source image", IMG); Cvnamedwindow ("ROI image",1); Cvshowimage ("ROI image", IMG2); while(1) {if(Cvwaitkey ( -) == -) Break; } Cvdestroywindow ("source image"); Cvdestroywindow ("ROI image"); Cvreleaseimage (&IMG); Cvreleaseimage (&IMG2);}
Display effects such as:
On the left is the original image, the right is the image to set the ROI area display
Let's talk about how to set the ROI region in the optical flow method, which plays an important role in the denoising of moving object detection and tracking using optical flow method.
Look at the code:
/** description:tracking Moving object based on optical flow * author:liulongpo* Date: -Years3Month8Day +: -: -**/...Set the area of interest and filter out irrelevant parts//area of interest is the upper-left coordinate ( the,0) Width is the, height is -The rectangular cvrect rect= cvrect ( the,0, the, -); Iplimage *imageroi = Cvcreateimage (Cvgetsize (Cvqueryframe (Capture)), ipl_depth_8u,1); Initializes the image, and all the values of the image matrix are0Cvzero (Imageroi); Set the image's area of interest Cvsetimageroi (Imageroi, rect); This sentence is necessary, otherwise you cannot draw a corner Cvset (Imageroi,cvscalar (255)); Releases the ROI of an area of interest that is set in image images, corresponding to Cvsetimageroi Cvresetimageroi (Imageroi);...Optical flow detection Cvgoodfeaturestotrack (SRC_IMG1, eig_img, temp_img, G_corners1, &corner_count, Qlevel, MinDist, ImageRO I);
The effect is as follows:
This is the use of ROI to remove the unwanted part of the optical flow method tracking effect.
The second picture is our area of interest rectangle, here is when the video source jitter, depicted the corner point, just to see the ROI Local.
Setting ROI region in Opencv_image and optical flow method