Setting ROI region in Opencv_image and optical flow method

Source: Internet
Author: User

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 (&AMP;IMG); Cvreleaseimage (&AMP;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

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.