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
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.