admin管理员组文章数量:1623803
1,背景
在使用opencv3.4.1版本时,遇到cvCreateFileCapture获取对象为NULL的问题,如下显示报错:
[ INFO:0] VIDEOIO: Enabled backends(5, sorted by priority): FFMPEG(1000); MSMF(990); DSHOW(980); CV_IMAGES(970); CV_MJPEG(960)
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:940)
warning: sample.mp4 (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:941)
2,原因
导致这种情况出现是由于使用了已经废弃的C-api,而没用使用C++ ap。opencv 1.0的编码方式未来不会继续维护了。
问题代码:
CvCapture *file;
const char *filename = "sample.mp4";
file = cvCreateFileCapture(filename);
if (!file)
{
printf("Failed to open file(%s)\n", filename);
return;
}
3,新标准代码方式
cv::VideoCapture capture; // c++ classes !
capture.open(filename);
if (! capture.isOpened())
{
printf("Failed to open file(%s)\n", filename);
return -1;
}
int fps = (int)capture.get(cv::CAP_PROP_FPS);
double width = capture.get(cv::CAP_PROP_FRAME_WIDTH);
double height = capture.get(cv::CAP_PROP_FRAME_HEIGHT);
int frameNum = (int)capture.get(cv::CAP_PROP_FRAME_COUNT);
printf("File(%s), width(%f), height(%f) fps (%d)\n", filename, width, height, fps);
cv::Mat frame;
for (;;) {
capture >> frame;
if (frame.empty())
break;
cv::imshow("cv", frame);
cv::waitKey(30);
}
本文标签: enabledbackendsOpencvVIDEOIOffmpeg
版权声明:本文标题:Opencv VIDEOIO: Enabled backends(5, sorted by priority): FFMPEG(1000) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1728896629a1178495.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论