使用opencv简单的播放AVI程序(40行)
生活随笔
收集整理的這篇文章主要介紹了
使用opencv简单的播放AVI程序(40行)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
學習OPENCV的第一個例子
#include <highgui.h> #include <cassert> #include <iostream> #include <Windows.h> using namespace std; void OnTrackbarSlide(int pos);int g_slider_position = 0; CvCapture *g_capture = NULL; int main(int argc , char ** argv) {assert(argc == 2);cvNamedWindow("Example2",CV_WINDOW_AUTOSIZE);g_capture = cvCreateFileCapture(argv[1]);assert(g_capture != NULL);int frames = (int) cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);int fps = (int) cvGetCaptureProperty(g_capture,CV_CAP_PROP_FPS);const int step_time = 1000 / fps ;if(frames != 0){cvCreateTrackbar("Position","Example2",&g_slider_position,frames,OnTrackbarSlide);}IplImage *frame ;while(1){frame = cvQueryFrame(g_capture);if(frame == NULL)break;cvShowImage("Example2",frame);if(++g_slider_position % fps == 0)cvSetTrackbarPos("Position","Example2",++g_slider_position);char c = cvWaitKey(step_time);if(c == 27)break;}cvReleaseCapture(&g_capture);cvDestroyWindow("Example2");}void OnTrackbarSlide(int pos) {cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,pos); } OnTrackbarSlide(int pos)為滑塊的回調函數.別的函數可以忘文生義
運行之前請安裝好opencv庫,再在依賴庫中設置好比如我用的opencv 2.1?
?cvcore210d.lib cv210d.lib highgui210d.lib
總結
以上是生活随笔為你收集整理的使用opencv简单的播放AVI程序(40行)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL批量提交修改业务
- 下一篇: zabbix触发器表达式