OpenCV學習筆記_播放視訊及重新整理跟蹤條
阿新 • • 發佈:2019-01-27
#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; }