Read data from video files--convert data to grayscale--candy edge detection for images

Source: Internet
Author: User

//read data from video files--convert data to grayscale--candy edge detection for images//Sandy//Time: 2015-10-10#include <cv.h>#includeintMainintargcChar*argv[]) {    //preparatory workcvcapture* Capture=cvcreatefilecapture ("E:\\videos\\xx.avi");//to point the capture variable to a video file    if(!capture)return-1;//Check if the function is successful//Read the video//method One: Use Cvgrab (Grab) Frame () to copy the video to memory space,//then use Cvretrieve (retrieve) Frame () to process the read-in data//method Two: Using Cvqueryframe () instead of a method of two functions//Declaration VariablesIplimage *vd_frame;//a video for storing colorIplimage *gray_frame;//used to store grayscale imagesIplimage *canny_frame;//Canny edge detection diagram//Declaration WindowCvnamedwindow ("Video",0); Cvnamedwindow ("Gray",0); Cvnamedwindow ("Canny",0); //Initialization of variablesVd_frame =Cvqueryframe (Capture); Gray_frame= Cvcreateimage (Cvgetsize (vd_frame), ipl_depth_8u,1); Canny_frame= Cvcreateimage (Cvgetsize (vd_frame), ipl_depth_8u,1);  while(1){        //conversion functions for different image formats Cvconvertimage (const cvarr* src (source), Cvarr DST (target), int flag=0)//Canny edge detection function Cvcanny (const CVARR * Image,cvarr *edges,double threshold One, double threshold two, int operator kernel size)//The small threshold is used to control the edge link, and the large threshold is used to control the initial segmentation of the edge. Cvconvertimage (Vd_frame,gray_frame,0);//Flag=1 will get an inverted image.Cvcanny (Vd_frame,canny_frame,Ten, -,3);//threshold One, smaller can buckle more edges. The greater the threshold of two, the less the buckle.//ShowCvshowimage ("Video", Vd_frame); Cvshowimage ("Gray", Gray_frame); Cvshowimage ("Canny", Canny_frame); CharC=cvwaitkey ( -); if(c== -) Break; Vd_frame=Cvqueryframe (Capture); }    //querying and setting various properties of a video//releasing the cvcapture structureCvreleasecapture (&capture);    Cvdestroyallwindows (); return 0;}

Read data from video files--convert data to grayscale--candy edge detection for images

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: 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.