Create a program to read and display video files, and use the slider bar to control the playback of video files. A slider is used to control the video playback position, jumping in 10 steps. Another slider to control stop/play
/*Create a program to read and display video files, and use the slider bar to control the playback of video files. A slider is used to control the video playback position, jumping in 10 steps. Another slider to control stop/play*/#include<cv.h>#includeintG_slider_position =0; Cvcapture* G_capture =NULL;intindex =0;BOOLFlag =true;intG_slider_position1 =0;voidOntrackbarslider (intPOS) {Cvsetcaptureproperty (g_capture, Cv_cap_prop_pos_frames, POS); //gets the properties of the video as a number of framesindex =Pos;}voidPlay_pause (intPOS) { if(pos = =0) {flag=true; } Else{flag=false; }}intMain () {Cvnamedwindow ("Main", cv_window_autosize); G_capture= Cvcreatefilecapture ("1.avi"); intFrames = (int) Cvgetcaptureproperty (g_capture, Cv_cap_prop_frame_count); //get the total number of frames in a video total number of frames in a video file if(frames!=0) {Cvcreatetrackbar ("position","Main", &g_slider_position, frames, ontrackbarslider); //sets the position of the slider and is named position the slider bar's sliding position in the window main shows the maximum value of the slider each time the slider changes the callback functionCvcreatetrackbar ("Position1","Main", &g_slider_position1,1, Play_pause); } Else{printf ("Read Video failed\n"); } iplimage*frame; Cvsettrackbarpos ("position","Main",1); //set the value of the slider barCvsettrackbarpos ("Position1","Main",0); while(1) {Frame=Cvqueryframe (g_capture); //read the contents of a video file individually by frame Charc = Cvwaitkey (Ten); if(c = = -) Break; Cvshowimage ("Main", frame); Cvsettrackbarpos ("position","Main", index); //sets the position of the current slider bar if(flag) {Index= index +Ten; Cvsetcaptureproperty (G_capture, Cv_cap_prop_pos_frames, index); //get the properties of a video } Else{cvsetcaptureproperty (g_capture, Cv_cap_prop_pos_frames, index); //Gets the video is the attribute}} cvreleasecapture (&g_capture); Cvdestroywindow ("Main"); return 0;}
Create a program to read and display video files, and use the slider bar to control the playback of video files. A slider is used to control the video playback position, jumping in 10 steps. Another slider to control stop/play