//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