演示 :一个带有滚动条的播放视频的代码。
#include #include #include #include #include #include
using using #pragma
int g_slider_position = 0; int i = 0; CvCapture* g_capture = NULL; void onTrackingbarSlide(int { i = pos; cvSetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES, pos); }
int main(int { cvNamedWindow("Example3", CV_WINDOW_NORMAL); g_capture = cvCreateFileCapture("F:\\life\\opencv\\BuildingCordovaAppsWithVS_high.mp4");
int frames = (int)cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT); if (frames != 0) { cvCreateTrackbar("Position", "Example3", &g_slider_position, frames, onTrackingbarSlide); }
IplImage* frame; while (1) { i++; frame = cvQueryFrame(g_capture); if (!frame) break; cvShowImage("Example3", frame); char c = cvWaitKey(33); if (c == 27) break;
cvSetTrackbarPos("Position", "Example3", i); }
cvReleaseCapture(&g_capture); cvDestroyWindow("Example3");
return 0; } |