First, add the following lib file to "project properties-" Configure properties-"linker-" input-"and add dependencies:
opencv_imgproc220d.lib opencv_legacy220d.lib opencv_ml220d.lib opencv_core220d.lib opencv_highgui220d.lib opencv_video220d.lib
// 4-4.cpp: defines the entry point of the console application. // # Include "stdafx. H "# include <opencv/cv. h> # include <opencv/highgui. h>/* int g_switch_value = 1; void switch_off_function () {printf ("Pause \ n") ;}; // You cocould do something with these functions toovoid switch_on_function () {printf ("Run \ n") ;}; void switch_callback (INT position) {If (position = 0) {switch_off_function () ;}else {switch_on_function ();}} int main () {iplimage * frame; cvcapture * g_capt Ure = NULL; If (! (G_capture = cvcreatefilecapture ("C: \ test. avi ") {printf (" failed to open % s \ n "," C: \ test. avi "); Return-1;} cvnamedwindow (" slidercontrol ", 1); cvcreatetrackbar (" Switch "," slidercontrol ", & g_switch_value, 1, switch_callback); While (1) {If (g_switch_value) {frame = cvqueryframe (g_capture); If (! Frame) break;} cvshowimage ("slidercontrol", frame); If (cvwaitkey (10) = 27) break;} cvreleasecapture (& g_capture); cvdestroywindow ("slidercontrol "); return (0);} */INT g_switch_value = 1; int g_slider_position = 0; cvcapture * g_capture = NULL; void ontrackbarslide (int pos) {cvsetcaptureproperty (g_capture, cv_cap_prop_pos_frames, pos);} void switch_callback (INT position) {If (position = 0) {PRI Ntf ("Pause \ n");} else {printf ("On \ n") ;}} int main () {cvnamedwindow ("test vedio slide", cv_window_autosize ); g_capture = cvcreatefilecapture ("C: \ test. avi "); int frames = (INT) cvgetcaptureproperty (g_capture, cv_cap_prop_frame_count); int framerate = (INT) cvgetcaptureproperty (g_capture, cv_cap_prop_fps); If (frames! = 0) {cvcreatetrackbar ("Switch", "test vedio slide", & g_switch_value, 1, switch_callback); cvcreatetrackbar ("position", "test vedio slide", & g_slider_position, frames, ontrackbarslide);} iplimage * frame; while (g_slider_position <frames) {If (g_switch_value = 1) {frame = cvqueryframe (g_capture); If (! Frame) break; cvshowimage ("test vedio slide", frame); char c = cvwaitkey (framerate); cvsettrackbarpos ("position", "test vedio slide", g_slider_position ); ontrackbarslide (g_slider_position); If (C = 27) break; g_slider_position ++;} else {If (cvwaitkey (10) = 27) break ;}} cvreleasecapture (& g_capture); cvdestroywindow ("test vedio slide ");}