OpenCV视频播放方法
今天折腾了一下OpenCV的视频播放功能,希望能对项目又帮助~
代码还是非常easy的,仅仅是之前遇到点小麻烦,找不到cvCreateFileCapture函数的定义,花了一两个小时
Makefile:
SOURCE_FILE := play_video.c OBJECT_FILE := play_video.o CFLAGS = -Wall -Wconversion -O3 `pkg-config --cflags opencv` LIBS = `pkg-config --libs --cflags opencv` complie: gcc $(CFLAGS) -c $(SOURCE_FILE) $(LIBS) link: gcc $(CFLAGS) $(OBJECT_FILE) -o ./a.out $(LIBS) clean: rm -rf ./*.o ./a.out
/************************************************************************** code writer : EOF code date : 2014.10.22 code file : videos.c e-mail : jasonleaster@gmail.com jasonleaster@163.com code decription: This is the demo for how to play a vedio by OpenCV. If you find something wrong with my code, please touch me by e-mail.Thank you. ****************************************************************************/ #include <stdio.h> //#include "opencv2/highgui/highgui_c.h" //#include "opencv2/imgproc/imgproc_c.h" #include "highgui.h" int main(int argc,char* argv[]) { CvCapture* capture = cvCreateFileCapture ("./B.avi"); char* win_name = "Hello World"; if(!capture) { printf("No capture"); return 1; } cvNamedWindow(win_name,CV_WINDOW_AUTOSIZE); IplImage* frame; float ratio = 0; char temp = 0; while(1) { frame = cvQueryFrame(capture); if(!frame) { break; } cvShowImage(win_name,frame); temp = cvWaitKey(33); if(temp == 27) { break; } } cvReleaseCapture(&capture); cvDestroyWindow(win_name); return 0; }
总体的框架就这样。能够玩视频~(≧▽≦)/~啦啦啦
版权声明:本文博主原创文章,博客,未经同意不得转载。