#include <cv.h>
#include <highgui.h>
using namespace std;
//记录当前位置
int g_slider_position = 0;
CvCapture* g_capture = NULL;
void onTrackbarSlide(int pos){
//设置视频属性
cvSetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES, pos);
}
int main()
{
//创建窗口
cvNamedWindow("test_demo1", CV_WINDOW_AUTOSIZE);
//载入文件
g_capture = cvCreateFileCapture("E:\\电影\\See You Again_超清.mp4");
//获取视频帧数
int frames = (int)cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT);
if (frames != 0){
//创建跟踪条
cvCreateTrackbar("Position", "test_demo1", &g_slider_position, frames, onTrackbarSlide);
}
IplImage* frame;
while (1){
//获取当前帧数
g_slider_position = (int)cvGetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES);
//刷新跟踪条
cvCreateTrackbar("Position", "test_demo1", &g_slider_position, frames, onTrackbarSlide);
frame = cvQueryFrame(g_capture);
if (!frame){
break;
}
//显示当前帧的内容
cvShowImage("test_demo1", frame);
//c为用户在键盘上的输入,27为esc键的ASCII的值
char c = cvWaitKey(33);
if (c == 27){
break;
}
}
//释放空间
cvReleaseCapture(&g_capture);
//销毁窗口
cvDestroyWindow("test_demo1");
return 0;
}
OpenCV学习笔记_播放视频及刷新跟踪条
最新推荐文章于 2024-02-28 13:26:09 发布