c++ - OpenCV - getting the slider to update its position during video playback -
i've picked 'learning opencv' , have been trying of code examples/exercises. in code snippet, want slider update position each video frame change, reason won't work (the picture freezes following code):
#include "cv.h" #include "highgui.h" int g_slider_position = 0; cvcapture* g_capture = null; void ontrackbarslide(int pos) { cvsetcaptureproperty(g_capture, cv_cap_prop_pos_frames, pos); } int main(int argc, char** argv) { cvnamedwindow("the tom 'n jerry show", cv_window_autosize); g_capture = cvcreatefilecapture(argv[1]); int frames = (int) cvgetcaptureproperty( g_capture, cv_cap_prop_frame_count ); if (frames != 0) { cvcreatetrackbar( "position", "the tom 'n jerry show", &g_slider_position, frames, ontrackbarslide ); } iplimage* frame; while (1) { frame = cvqueryframe(g_capture); if (!frame) break; cvsettrackbarpos( "position", "the tom 'n jerry show", ++g_slider_position ); cvshowimage("the tom 'n jerry show", frame); char c = cvwaitkey(33); if (c == 27) break; } cvreleasecapture(&g_capture); cvdestroywindow("the tom 'n jerry show"); return 0; }
any idea how slider , video work intended?
this actual working code // program add updating trackbar video #include <cv.h> #include <highgui.h> int g_slider_position = 0; cvcapture* video_capture = null; void ontrackbarslide(int current_frame) { current_frame = g_slider_position; cvsetcaptureproperty(video_capture,cv_cap_prop_pos_frames,current_frame); } int main( int argc, char** argv ) { cvnamedwindow( "video", cv_window_autosize ); video_capture = cvcreatefilecapture( "crowdy.avi"); int no_of_frames = (int) cvgetcaptureproperty(video_capture,cv_cap_prop_frame_count); if( no_of_frames!= 0 ) { cvcreatetrackbar("slider","video",&g_slider_position,no_of_frames,ontrackbarslide); } iplimage* frame; while(1) { frame = cvqueryframe( video_capture ); if( !frame ) break; cvshowimage( "video", frame ); cvsettrackbarpos("slider","video",++g_slider_position); char c = cvwaitkey(33); if( c == 27 ) break; } cvreleasecapture( &video_capture ); cvdestroywindow( "video" ); return(0); }
Comments
Post a Comment