opencv读取avi视频并抽取帧
【摘要】 opencv读取avi视频并抽取帧
/
编辑 删除
#include "stdafx.h"
#include <opencv2/opencv.hpp>
using names...
opencv读取avi视频并抽取帧
/
#include "stdafx.h"
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
//cvNamedWindow("test", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateFileCapture("G://test.avi");//cvcapture 和 vediocapture 区别:一个是c一个是c++
//获取视频总帧数
int numFrames = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
cout << "视频总帧数为:" << numFrames << endl;
//获取视频fps
int fps = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
cout << "fps:" << fps << endl;
IplImage* frame;
int pos = 0;
while (1)
{
//抽取帧
cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, pos);
cout << pos << "/" << numFrames << endl;
frame = cvQueryFrame(capture);
//将IplImage转化为mat,方便以后进行处理
Mat mat = cvarrToMat(frame);
imshow("test", mat);
char c = cvWaitKey(33);
if (c == 27)
break;
//调整抽取帧的位置
pos+=24;
}
cvReleaseCapture(&capture);
cvDestroyWindow("test");
}
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
//cvNamedWindow("test", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateFileCapture("G://test.avi");//cvcapture 和 vediocapture 区别:一个是c一个是c++
//获取视频总帧数
int numFrames = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
cout << "视频总帧数为:" << numFrames << endl;
//获取视频fps
int fps = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
cout << "fps:" << fps << endl;
IplImage* frame;
int pos = 0;
while (1)
{
//抽取帧
cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, pos);
cout << pos << "/" << numFrames << endl;
frame = cvQueryFrame(capture);
//将IplImage转化为mat,方便以后进行处理
Mat mat = cvarrToMat(frame);
imshow("test", mat);
char c = cvWaitKey(33);
if (c == 27)
break;
//调整抽取帧的位置
pos+=24;
}
cvReleaseCapture(&capture);
cvDestroyWindow("test");
}
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/78830653
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)