上一个博文只是进行了视频播放,这里加上进度条。
下面是修改好的代码:
#include <cv.h> #include <highgui.h> /* * tan@ubuntu:~/cv$ g++ AVIPlayerPlus.cpp -o AVIPlayerPlus `pkg-config opencv --cflags --libs` * tan@ubuntu:~/cv$ ./AVIPlayerPlus ../apple.avi * */ #define KEY_ESC 27 #define DELAY_TIME 33 CvCapture *g_capture = NULL; void onTrackbarSlide(int cur_pos) { /* set capture to some position */ cvSetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES, cur_pos); } int main(int argc,char **argv) { int slider_position = 0; cvNamedWindow("good_player", CV_WINDOW_AUTOSIZE); g_capture = cvCreateFileCapture(argv[1]); /* create trackbar UI */ int frame_count = cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT); if(0 != frame_count) cvCreateTrackbar("bar_name", "good_player", &slider_position, frame_count, onTrackbarSlide); /* Real function */ IplImage *frame; while (true) { frame = cvQueryFrame(g_capture); if (!frame) break; cvShowImage("good_player",frame); char c = cvWaitKey(DELAY_TIME); if (KEY_ESC == c) break; } cvReleaseCapture(&g_capture); cvDestroyWindow("good_player"); return 0; }
这里的关键函数是
cvCreateTrackbar和
onTrackbarSlide
这两个函数分别创建了了进度条,另一个函数是cvCreateTrackbar的回调函数。
下面是效果(ubuntu默认不支持的AVI可以播放啦!):