OpenCV播放视频,并可设置进度
2017-03-06 21:22
411 查看
最近在看《Learning OpenCV》这本书,然而在讲这点时留下了一句话:
Finally, we did not include the extra tidbit of code needed to make the slider move as the video plays. This is left as an exercise for the reader.
练习。。。
果然不能愉快地偷懒了。
以下是代码,敲下来日后也好找。
俺当然要支持龙母!!
Finally, we did not include the extra tidbit of code needed to make the slider move as the video plays. This is left as an exercise for the reader.
练习。。。
果然不能愉快地偷懒了。
以下是代码,敲下来日后也好找。
#include "stdafx.h" #include <opencv2/highgui/highgui.hpp> #include <opencv/cv.hpp> int g_slider_position = 0;//滚动条的位置 int ProgressBar_Number;//通过调用获取函数得到的当前视频的进度 CvCapture* g_capture = NULL;//视频文件结构体 //回调函数 void onTrackbarSlide(int pos) { cvSetCaptureProperty( g_capture, CV_CAP_PROP_POS_FRAMES,//用帧数来设置读入位置,AVI_RATIO代替FRAMES实现按视频长度比例来设 //置读入位置 pos ); } int main() { cvNamedWindow("Video_ProgressBar", CV_WINDOW_AUTOSIZE); g_capture = cvCreateFileCapture("[权力的游戏][第五季]第08集_bd.mp4"); int frames = (int)cvGetCaptureProperty( g_capture, CV_CAP_PROP_FRAME_COUNT ); if (frames != 0) { cvCreateTrackbar( "ProgressBar",//滚动条的名字 "Video_ProgressBar",//窗口的名字 &g_slider_position,//滚动条的位置 frames,//总帧数 onTrackbarSlide//回调函数 ); } IplImage* frame; while (1) { frame = cvQueryFrame(g_capture); if (!frame) break; //获取滚动条在视频中的位置,自动更新滚动条,但在主线程中更新UI会使播放看起来比不更新滚动条要卡顿 **ProgressBar_Number = (int)cvGetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES);** cvSetTrackbarPos("ProgressBar", "Video_ProgressBar", ProgressBar_Number);//设置进度条的位置 cvShowImage("Video_ProgressBar", frame); char c = cvWaitKey(33); if (c == 27) break;//ESC键 } // Release memory and destroy window cvReleaseCapture(&g_capture); cvDestroyWindow("Video_ProgressBar"); return(0); }
俺当然要支持龙母!!
相关文章推荐
- opencv avi视频播放带进度条
- Opencv中视频播放与进度控制
- OpenCV实现视频播放和进度条
- opencv2/3播放视频实现进度条显示拖动、快进、快退、逐帧播放、显示当前帧于图像
- opencv视频播放和进度条
- opencv实现播放视频文件(AVI) 并设置播放的进度条
- OpenCV学习笔记(3)——进度条视频播放控制
- linux下使用opencv接口函数控制视频播放进度
- Opencv实现视频播放与进度控制
- openCV—可调节进度视频播放
- Opencv中视频播放与进度控制
- OpenCV视频进度播放控制
- DirectShow 制作在Unity3D中可以设置进度的视频播放插件
- opencv录制与播放视频设置
- OpenCV 播放视频文件
- opencv [c++版] 学习笔记(2) 在MFC基于对话框界面上播放视频
- openCV播放视频的程序
- 1.0.2-学习Opencv与MFC混合编程之---为播放AVI视频添加滑动条
- 1.0.2-学习Opencv与MFC混合编程之---为播放AVI视频添加滑动条
- windows2003 iis中播放flv格式的视频设置