如何读取视频文件以在openCV中使用? [英] How can I read a video file for use in openCV?

查看:504
本文介绍了如何读取视频文件以在openCV中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从avi文件中读取视频文件,然后逐帧输入,以便在openCV中处理。
我如何做到这一点?
在openCV中是否有函数?

解决方案

使用视频片段

从视频片段中捕获帧



相机:

  CvCapture * capture = cvCaptureFromCAM //从视频设备捕获0#

正在从文件初始化捕获:

  CvCapture * capture = cvCaptureFromAVI(infile.avi); 
捕获一个框架:

IplImage * img = 0;
if(!cvGrabFrame(capture)){//捕获帧
printf(Could not grab a frame\\\
\7);
exit(0);
}
img = cvRetrieveFrame(capture); //检索捕获的帧

要同时从多个摄像机获取图像,请先从每个摄像机抓取图像。抓取完成后检索捕获的图像。



释放捕获源:

  cvReleaseCapture(& capture); 

请注意,设备捕获的图像由捕获功能。没有必要明确地释放它。


I want to read a video file from an "avi file" and then enter it frame by frame to process it in openCV. How can I do that? Are there functions for that in openCV? Should I use a video reading framwork?

What are good frameworks for reading video files?

解决方案

Working with video sequences
Capturing a frame from a video sequence

Initializing capture from a camera:

CvCapture* capture = cvCaptureFromCAM(0); // capture from video device #0

Initializing capture from a file:

CvCapture* capture = cvCaptureFromAVI("infile.avi");
Capturing a frame:

IplImage* img = 0; 
if(!cvGrabFrame(capture)){              // capture a frame 
    printf("Could not grab a frame\n\7");
    exit(0);
}
img=cvRetrieveFrame(capture);// retrieve the captured frame

To obtain images from several cameras simultaneously, first grab an image from each camera. Retrieve the captured images after the grabbing is complete.

Releasing the capture source:

cvReleaseCapture(&capture);

Note that the image captured by the device is allocated/released by the capture function. There is no need to release it explicitly.

这篇关于如何读取视频文件以在openCV中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆