Implementing the drag of the video bar requires using the global variable g_slider_position, and the callback function Ontrackbarslider ().
The drag bar is generated by the function Cvcreatetrackbar () function, which is called as follows:
1 cvcreatetrackbar ("position",2 " Original",3 &g_slider_position,4 Frames,5 ontrackbarslider); 6 }
"Position" is the drag bar name, "Original" is the display window name, &g_slider_position is the drag bar position, frames is the total frame number of the video, Ontrackbarslide ().
To implement the drag bar changes with the video playback, you need to add a global variable cur_frame to read the current number of video frames in the loop that plays the video
Cur_frame = Cvgetcaptureproperty (g_capture,cv_cap_prop_pos_frames);
by function Cvsettrackbarpos ("position", "Original", cur_frames);
The specific code for implementing canny detection is
1#include"highgui.h"2#include"cv.h"3 4 intG_slider_position =0;5cvcapture* g_capture =NULL;6 intCur_frame =0;7 8 voidOntrackbarsilder (intPOS) {9 if(Cur_frame! =POS) {Ten Cvsetcaptureproperty ( One G_capture, A Cv_cap_prop_pos_frames, - POS); - } the } - - intMainintargcChar**argv) - { +Cvnamedwindow ("Original", cv_window_autosize); -G_capture = Cvcreatefilecapture (argv[1]); + A intFrames = (int) Cvgetcaptureproperty ( at G_capture, - Cv_cap_prop_frame_count - ); - - if(Frames! =0 ) - { inCvcreatetrackbar ("position", - "Original", to&G_slider_position, + frames, - ontrackbarsilder); the } * $iplimage*frame;Panax Notoginsengiplimage*Out ; -iplimage*O_can; the + while(1){ ACur_frame =Cvgetcaptureproperty (g_capture,cv_cap_prop_pos_frames); theCvsettrackbarpos ("position","Original", cur_frame); +frame =Cvqueryframe (g_capture); -out = Cvcreateimage (Cvgetsize (frame), frame->depth,1); $O_can = Cvcreateimage (Cvgetsize (frame), frame->depth,1); $ - Cvcvtcolor (frame,out,cv_rgb2gray); -Cvcanny (Out,o_can, -, the,3); the if(!frame) Break; -Cvshowimage ("Original", O_can);Wuyi Charc = Cvwaitkey ( -); the if(c = = -) Break; - } Wu -Cvreleasecapture (&g_capture); AboutCvdestroywindow ("Original"); $ - return 0; -}
This way of adding a drag bar does not cause video playback to stutter, and using the cur_frame++ method in the playback loop will cause the video to stutter.
This method can be video video canny detect smooth playback
Cvcanny (const cvarr* image, cvarr* edges, double threshold1,
Double threshold2, int aperture_size cv_default (3));
The first parameter is the input image, the second parameter is the output image, the third is the low threshold value, the fourth is the high threshold, the fifth is the canny operator size, the default is 3;
It is important to note that both the input and output images of the canny detection are grayscale images.
The complete code is as follows:
OPENCV read the video, with the play scrolling video bar, canny detection.