OpenCV - getting the slider to update its position during video playback

后端 未结 6 1901
-上瘾入骨i
-上瘾入骨i 2020-12-28 21:12

I\'ve picked up \'Learning OpenCV\' and have been trying some of the code examples/exercises. In this code snippet, I want to get the slider to update its position with each

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 21:34

    This is the actual working code
    
    
    
    // PROGRAM TO ADD A UPDATING TRACKBAR TO A VIDEO
    
    #include 
    #include 
    
    
    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);
    }
    

提交回复
热议问题