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

后端 未结 6 1920
-上瘾入骨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条回答
  •  -上瘾入骨i
    2020-12-28 21:33

    This seems a bit complicated to me. I used the cvGetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES) call to retrieve the current frame and used this to update the slider.

    The callback function is then used just to change the position within g_capture.

    So the call back is:

    //Call back for slider bar
    void onTrackbarSlide(int pos) {
        cvSetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES, pos);
    }
    

    And the loop is:

    IplImage* frame; //Frame grabbed from video
    while(1) {
        frame = cvQueryFrame( g_capture );
        if (!frame ) break;
        cvShowImage( "Example2", frame );
    
        g_frame_count = (int) cvGetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES);
    
        cvSetTrackbarPos("Position","Example2", g_frame_count);
    
        char c = cvWaitKey(33);
        if ( c == 27 ) break;
    }
    

    Where the g_ variables are global.

提交回复
热议问题