說明:OpenCV是計算機視覺庫,所以用在圖片或視頻處理上,故播放的視頻暫時沒有聲音
軟件:用OpenCV製作視頻控制播放器(無聲音)
功能說明:新建播放窗口,添加進度條可以拖動視頻播放。
流程圖:
功能說明:
1. 新建進度條 cvCreatTrackbar("","",&,frames,callback)
2、獲取總幀數 cvGetCaptureProperty(&,id)
double cvGetCaptureProperty( CvCapture* capture, int property_id );capture 視頻獲取結構。property_id 屬性標識。可以是下面之一:CV_CAP_PROP_FRAME_COUNT - 視頻文件中幀的總數
3.回調函數 cvSet(&,id, pos)
int cvSetCaptureProperty( CvCapture* capture, int property_id, double value )property_id 屬性標識符。可以是下面之一:CV_CAP_PROP_POS_FRAMES - 單位爲幀數的位置(只對視頻文件有效)
源代碼:
#include”cv.h”
#include”highgui.h”
int g_slider_position=0;
CvCapture* g_capture =NULL;
void CvTrackcalllback(int pos)
{
cvSetCaptureProperty( g_capture, CV_CAP_PROP_POS_FRAMES, pos );
}
int main(int argc, char** argv)
{
cvNamedWindow("Example3",CV_WINDOW_AUTOSIZE);
g_capture = cvCreateFileCapture("視頻路徑");
int frames = (int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);
if(frames!=0)
{
cvCreateTrackbar("Test","Example3",&g_slider_position,frames,CvTrackcalllback);
}
IplImage* frame;
while(1)
{
frame = cvQueryFrame(g_capture)
cvShowImage("Example3",frame);
cvWaitKey(0);
}
return 0;
}
運行結構截圖如下:
有問題,願意與大家交流!