OpenCV 尝试读取或写入视频文件导致 VIDEOIO 异常“找不到起始编号"(icvExtractPattern) [英] OpenCV trying to read or write to video file causes VIDEOIO exception "Can't find starting number" (icvExtractPattern)

查看:1908
本文介绍了OpenCV 尝试读取或写入视频文件导致 VIDEOIO 异常“找不到起始编号"(icvExtractPattern)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,对于学校项目,我尝试使用 cv::VideoCapture 打开一个 .avi 文件以对其进行一些图像处理.此外,我正在尝试从我的(笔记本电脑)相机录制视频并将其保存到文件 out.avi.两次我都或多或少地遇到了相同的异常.我在 Linux Mint 上使用 OpenCV 4.1.2 和 CLion.

So for a school project, I am trying to use cv::VideoCapture to open a .avi file to perform some image processing on it. Also, I am trying to record the video from my (Laptop) camera and save it to a file out.avi. Both times I encountered more or less the same exception. I am using OpenCV 4.1.2 and CLion on Linux Mint.

尝试使用 cv::VideoCapture vid(0); 效果很好,它显示了笔记本电脑摄像头的输出.但是,在指定要打开的视频文件的路径时,出现以下错误:

Trying to use cv::VideoCapture vid(0); works perfectly fine, it shows the output from the Laptop's camera. However, when specifying a path to a video file to open, I get the following error:

VIDIOC_REQBUFS: Inappropriate ioctl for device
[ERROR:0] global /home/aris/dev/opencv/modules/videoio/src/cap.cpp (116) open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.1.2-dev) /home/aris/dev/opencv/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): ../example_depth.avi in function 'icvExtractPattern'

当尝试使用以下方法创建 cv::VideoWriter 对象(将相机视频输出保存到文件)时:

When trying to create a cv::VideoWriter object (to save the camera video ouput to a file) using:

cv::VideoWriter vidWrit("out.avi", cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), 10, cv::Size(width, height), true);

我遇到了这个错误:

[ERROR:0] global /home/aris/dev/opencv/modules/videoio/src/cap.cpp (392) open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.1.2-dev) /home/aris/dev/opencv/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): out.avi in function 'icvExtractPattern'

看起来和另一个很相似.

Which looks kind of similar to the other one.

这是一个最小的例子(注意程序仍然在task == "write"中显示相机输出):

Here is a minimal example (note that the program still shows the camera output in task == "write"):

#include <opencv2/opencv.hpp>

int main ()
{
    std::string task = "write";
    if(task == "read") {    // Read from .avi file
        system("pwd");  // Print current path
        cv::VideoCapture vid("../example_depth.avi");   // Throws first exception "Inappropriate ioctl for device"

        int key = 0;
        cv::Mat frame;
        while (key != 27) {
            vid >> frame;
            if (frame.empty())
                break;

            cv::imshow("Video", frame);
            key = cv::waitKey(25);
        }
    } else if (task == "write") {   // Write Laptop video to file
        cv::VideoCapture vid(0);    // Video from camera

        int width = vid.get(cv::VideoCaptureProperties::CAP_PROP_FRAME_WIDTH);
        int height = vid.get(cv::VideoCaptureProperties::CAP_PROP_FRAME_HEIGHT);
        cv::VideoWriter vidWriter("out.avi", cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), 10, cv::Size(width, height), true);   // Throws second exception

        int key = 0;
        cv::Mat frame;
        while (key != 27) {
            vid >> frame;
            if (frame.empty())
                break;
            vidWriter.write(frame);

            cv::imshow("Video", frame);
            key = cv::waitKey(25);
        }
    }
    return 0;
}

这两天我一直在寻找解决方案.也许我缺少一些库或 OpenCV 没有正确安装,我不知道(是的,我试过重新编译"OpenCV).我使用了 this 制作所有 OpenCV 文件的教程.

I've been looking for a solution for two days now. Maybe I am missing some library or OpenCV didn't get installed correctly, I don't know about that (yes, I've tried 'recompiling' OpenCV). I used this tutorial to make all the OpenCV files.

推荐答案

我已经多次看到这个问题.首先检查视频的路径是否正确.在你的情况下,out.avi"应该存在.所以这可能是一个依赖或冲突问题.我的猜测是当后端视频编码器库与 OpenCV 冲突时会发生此错误.尝试重新安装库.我建议您按照 官方文档如果您一直遇到问题,请打开一个问题.

I've seen this issue a couple of times. First check if the path to the video is correct. In your case, "out.avi" should exist. So this is probably is a dependency or conflict issue. My speculation is that this error occurs when a backend video encoder library conflicts with OpenCV. Try reinstalling the libraries. I suggest you follow the instructions from the official documentation, and open an issue if you keep experiencing problems.

这篇关于OpenCV 尝试读取或写入视频文件导致 VIDEOIO 异常“找不到起始编号"(icvExtractPattern)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆