openCV读取.avi文件的视频捕获获取空框架
OpenCV read VideoCapture of .avi file get empty frame
我是OpenCV的新手,并尝试运行一个简单的程序,该程序读取.avi文件并逐帧在窗口中显示IT。我的系统是OSX El Capitan。这是我的代码:
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main( int argc, const char** argv )
{
Mat frame;
VideoCapture cap("crs01.avi");
if(!cap.isOpened()){ // check if we succeeded
cout << "Video not loaded!!" << endl;
return -1;
} else {
cout << "Loaded!!" << endl;
}
int count = cap.get(CV_CAP_PROP_FRAME_COUNT);
for(int i = 0; i < count; i++){
// while(true) {
cap >> frame;
if(!frame.empty()){
imshow("edges", frame);
} else {
cout << "EMPTY" << endl;
}
if(waitKey(30) >= 0)
break;
}
cap.release();
return 0;
}
但是,该程序总是会返回我空的框架。它可以打印"已加载",但之后它不断打印"空"。我已经在内置摄像头上尝试了此程序,即Videocapture Cap(0);以及读取其他.Avi文件,并且在两种情况下都可以正常工作。我还试图运行一个调试器,事实证明,"盖帽>>帧"行之后的框架确实是空的。
有人可以帮助我吗?这个问题与MAC系统有关系吗?预先感谢!
这是另一种做到的方法。
cv::VideoCapture mycap;
std::string fileName="PATH_TO_FILE//FILENAME";
mycap.open(fileName);
int totalFrameNumber = (int)mycap.get(CV_CAP_PROP_FRAME_COUNT);
cv::Mat newImg;
for (int counter = 0; counter<totalFrameNumber; counter++){
bool frameIsCorrect = mycap.read(newImg);
if (new_Img.cols>0)
{
cv::imshow("frame", newImg);
cv::waitKey(1); //or waitKey(0) to pause on every new frame for a key press
}
}
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 使用指针从C++中的数组中获取最大值
- 如何获取std::result_of函数的返回类型
- 如何在openssl-ecc中获取十六进制格式的私钥
- 使用Unreal C++获取VR耳机的世界位置/方向
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 从C字符串中获取奇怪的字符串长度
- 为什么我的for循环不能正确获取argv
- 在哪里可以从Android框架中获取原始的PCM数据
- WinAPI - 获取用于绘图的可滚动框架
- 如何在Qt框架中从视频中逐个获取帧
- 如何使用VLC-QT从视频中获取框架
- openCV读取.avi文件的视频捕获获取空框架
- 如何使用FFMPEG使用DXVA2来解码并获取框架
- 获取主框架窗口
- 尝试在Qt中获取自定义窗口框架时LNK2019问题
- 是否有一种方法可以从VS环境之外的MS单元测试框架中获取信息
- 在创建任何窗口之前,如何获取窗口框架的宽度