我怎样才能得到OpenCV的VideoCapture初始化时出了什么问题?

How can I get what went wrong in initialization of OpenCV's VideoCapture?

本文关键字:初始化 什么 问题 VideoCapture OpenCV      更新时间:2023-10-16

我想用OpenCV打开视频文件dt_passat.mpg。我使用以下代码:

#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main( int argc, char** argv )
{
    VideoCapture capture("dt_passat.mpg");
    if (!capture.isOpened()) {
        std::cerr << "ERR: capture is not opened" << std::endl;
        getchar();
        return -1;
    }
}

然而,它失败了,我不知道为什么。我怎么能得到问题的点与videoccapture的初始化(未找到文件/损坏的文件/未知的编解码器/等)?

不幸的是,OpenCV并不总是有最好的文档。

您可以尝试使用cvGetErrorStatus()查看内部错误代码,然后使用cvErrorStr()将其转换为可读字符串。看到http://opencv.willowgarage.com/documentation/c/core_utility_and_system_functions_and_macros.html cvGetErrStatus

opencv的图像/视频/相机IO和gui实际上只是为了获得样本数据进出测试算法,使一个真正的应用程序,你需要一个更强大的通用库系统的东西。

但是实际的图像处理算法质量相当不错。