C++ OpenCV读取.avi文件的视频捕获获取空帧
我是OpenCV新手,正在尝试运行一个简单的程序,读取.avi文件并在窗口中逐帧显示。我的系统是OSX El Capitan。这是我的密码:C++ OpenCV读取.avi文件的视频捕获获取空帧,c++,macos,opencv,opencv3.0,C++,Macos,Opencv,Opencv3.0,我是OpenCV新手,正在尝试运行一个简单的程序,读取.avi文件并在窗口中逐帧显示。我的系统是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 "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;
}
#包括“opencv2/objdetect/objdetect.hpp”
#包括“opencv2/highgui/highgui.hpp”
#包括“opencv2/imgproc/imgproc.hpp”
#包括“opencv2/core/core.hpp”
#包括
#包括
使用名称空间std;
使用名称空间cv;
int main(int argc,常量字符**argv)
{
垫架;
视频捕获cap(“crs01.avi”);
如果(!cap.isOpened()){//检查我们是否成功
cout这里有另一种方法
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
}
}
cv::VideoCapture mycap;
std::string fileName=“路径到文件//文件名”;
mycap.open(文件名);
int totalFrameNumber=(int)mycap.get(CV\u CAP\u PROP\u FRAME\u COUNT);
cv::Mat newImg;
用于(整数计数器=0;计数器0)
{
cv::imshow(“框架”,newImg);
cv::waitKey(1);//或waitKey(0)在每一个新帧上暂停一次按键
}
}
OP的具体问题是什么?您的代码应该如何解决?第2行-为什么是指针?第3行-在没有验证的情况下取消引用指针,在这种情况下是一个单位化指针。第4行-从double到int的隐式转换将导致警告。第5行-计数器未定义。第5+6行-为什么不只是for循环?第8行-frameIsCorrect
不再使用。第9行-imshow
未完全限定,字符串文本周围缺少右括号,未经验证就使用了newImg
。第10行-waitKey
未限定。谢谢Dan Masek。这是一条指导线,很久以前对我有用。