来自 AVI 的 OpenCV 帧捕获
OpenCV frame capture from AVI
我正在用openCV 2.2做一个项目。 我需要对 AVI 文件的每一帧进行处理,但是当我运行代码时,它只抓取文件的第一帧。 CV_CAP_PROP_POS_FRAMES似乎不起作用。 任何想法为什么不呢?
CvCapture* capture = cvCaptureFromAVI("test1.avi");
IplImage *img = 0;
if (!cvGrabFrame(capture)) {
printf("Error: Couldn't open the image file.n");
return 1;
}
int numFrames = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
int posFrame = 1;
for(int i =0; i <= numFrames; i++){
cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, i);
posFrame = cvGetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES);
img = cvGrabFrame(capture);
cvNamedWindow("Image:", CV_WINDOW_AUTOSIZE);
cvShowImage("Image:", img);
printf("%in",posFrame);
cvWaitKey(0);
cvDestroyWindow("Image:");
}
为什么不使用OpenCV 2.3尝试这种方式呢?我觉得更直接、更高效,更清晰:
VideoCapture _videoSource;
if(!_videoSource.open("test1.avi"))
{
exit(1); // Exit if fail
}
_videoSource.set(CV_CAP_PROP_CONVERT_RGB, 1);
Mat frame;
namedWindow("Image");
int posFrame;
while(1)
{
_videoSource >> frame;
posFrame=_videoSource.get(CV_CAP_PROP_POS_FRAMES);
imshow("output", frame);
return 0;
}
这样的事情应该有效。
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将OpenCV C++重写为EmguCV C#-如何使用指针
- OpenCV C++.快速计算混淆矩阵
- 在C++代码中包含opencv时,使用ctypes创建.so文件
- openCV读取.avi文件的视频捕获获取空框架
- 由OpenCV 2.4.6创建的AVI文件在应用程序退出时并不总是有效
- OpenCV显示编码在I420中的avi文件
- C++/OpenCV中视频的AVI大小(千字节)
- 来自 AVI 的 OpenCV 帧捕获
- OpenCV/无法打开AVI文件
- 如何使用OpenCV编写大于2GB的avi文件
- 使用opencv从帧创建divx编码的avi
- 为什么我无法在 openCV 中打开 avi 视频?
- 如何从磁盘加载Jpeg图像并创建视频文件?Avi等),而无需在c++中使用opencv
- OpenCV -如何从.ppm文件列表中生成.avi文件
- Opencv写摄像头输出到avi文件