概述
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
VideoCapture capture;
Mat frame;
const string source = "/home/gear/big_disk_c/wangjd/shipintest/789.mp4";
// frame= capture.open("789.mp4");
frame= capture.open(source);
if(!capture.isOpened())
{
printf("can not open ...n");
return -1;
}
printf("1213131n");
// namedWindow("output", CV_WINDOW_AUTOSIZE);
while (capture.read(frame))
{
imshow("output", frame);
waitKey(10);
}
capture.release();
return 0;
}
原因:路径。我这服务器有权限问题,写完整路径的话会报错。而且我生成的可执行文件和视频文件也不在同一个目录,…/789.mp4会读取不到,只有把两个放一起才能读取。后来发现
capture.open()的构造函数传入的是const string,于是 先实例化一个const string source,然后就可以写完整路径了,再传入入就ok了
const string source = "/home/gear/big_disk_c/wangjd/shipintest/789.mp4";
frame= capture.open(source);
最后
以上就是精明白猫为你收集整理的opencv c++ 读取视频报错 capture.isOpened()返回false的全部内容,希望文章能够帮你解决opencv c++ 读取视频报错 capture.isOpened()返回false所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复