• OpenCV视频播放方法



    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;
    }

    总体的框架就这样。能够玩视频~(≧▽≦)/~啦啦啦













    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    HDU
    HDU
    [JSOI2009]计数问题 二维树状数组BZOJ 1452
    THU 上机 最小邮票数 暴力枚举
    SJTU 机试 最小面积子矩阵 压缩+双指针
    SJTU 机试 数学
    Preprefix sum BZOJ 3155 树状数组
    [HNOI2004]树的计数 BZOJ 1211 prufer序列
    HDU 5009
    上下界网络流模型常见解法
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4829091.html
Copyright © 2020-2023  润新知