简体   繁体   English

Windows中的VideoCapture OpenCV 2.4.2错误

[英]VideoCapture OpenCV 2.4.2 error in windows

I have a problem using VideoCapture class with OpenCV 2.4.2 under windows XP 32bits. 我在Windows XP 32位下使用OpenCV 2.4.2的VideoCapture类时遇到问题。 It doesn't open any file or camera and fixing it's being a pain. 它没有打开任何文件或相机,并修复它是一个痛苦。 Im using visual studio 2010 but i have also tried the code in QTcreator with the same result. 我正在使用visual studio 2010,但我也在QTcreator中尝试了相同的结果。

The testing code is the following: 测试代码如下:

#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <iostream>
#include <string> 
#include <iomanip> 
#include <sstream> 

using namespace cv;
using namespace std;

int main()
{
    const char* videoPath = "C:/video/";
    string videoName = string(videoPath) + "avi.avi";
    VideoCapture cap(videoName);

    if(!cap.isOpened()) 
    {
        std::cout<<"Fail"<<std::endl;
        return -3;
    }
    return 0; 
}

The output is always '-3'. 输出始终为“-3”。 Qt Creator shows a warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:361) Qt Creator显示警告:打开文件时出错(../../modules/highgui/src/cap_ffmpeg_impl.hpp:361)

I debugged it and the problem appears in the first line of: 我调试了它,问题出现在第一行:

CvCapture* cvCreateFileCapture_FFMPEG_proxy(const char * filename)
{
    CvCapture_FFMPEG_proxy* result = new CvCapture_FFMPEG_proxy;
    if( result->open( filename ))
        return result;
    delete result;
#if defined WIN32 || defined _WIN32
    return cvCreateFileCapture_VFW(filename);
#else
    return 0;
#endif
}

in the cap_ffmpeg.cpp internal file. 在cap_ffmpeg.cpp内部文件中。

I have tested the same code in a mac under snow leopard and it works. 我已经在雪豹的Mac下测试了相同的代码并且它可以工作。 No surprises here since it must be a library issue. 这里没有惊喜,因为它一定是图书馆问题。 I have opened the avi file with the same path route using the c-function cvCapture easy and fast. 我使用c-function cvCapture轻松快速地打开了具有相同路径路径的avi文件。 I got all the dlls of 'C:\\opencv\\opencv\\build\\x86\\vc10\\bin' included in mi debug file. 我得到了mi调试文件中包含的所有'C:\\ opencv \\ opencv \\ build \\ x86 \\ vc10 \\ bin'的dll。 I got the tbb.dll and all the 'C:\\opencv\\opencv\\3rdparty\\ffmpeg' content included too. 我得到了tbb.dll和包含的所有'C:\\ opencv \\ opencv \\ 3rdparty \\ ffmpeg'内容。

This is drving me crazy so any help would be appreciated. 这让我疯了,所以任何帮助都会受到赞赏。

Thanks in advance. 提前致谢。

In my case, the same problem was resolved after deleting all opencv_***.dll files in C:\\Windows\\System32 . 在我的情况下,删除C:\\Windows\\System32所有opencv_***.dll文件后解决了同样的问题。 So, I use the dll files just through the path like "%PATH%;C: \\Program Files \\OpenCV2.4.2\\build\\x86\\vc10/bin" . 所以,我只是通过"%PATH%;C: \\Program Files \\OpenCV2.4.2\\build\\x86\\vc10/bin"类的路径使用dll文件。 Please try it. 请试一试。

I also faced with this problem and solved it by correct the path of the function: 我也遇到了这个问题并通过纠正函数的路径来解决它:

VideoCapture cap(videoName);

If the AVI file of videoName does't exist, it will be an error: 如果videoName的AVI文件不存在,则会出错:

(../../modules/highgui/src/cap_ffmpeg_impl.hpp:XXX)

where XXX represents the line number. 其中XXX代表行号。

I had the same issue with the open method whilst running under Windows 8 (64bit), opencv 2.4.10. 在Windows 8(64位),opencv 2.4.10下运行时,我遇到了与open方法相同的问题。 IDE is running in x86. IDE正在x86中运行。

I found that running the application in release configuration solved the problem. 我发现在发布配置中运行应用程序解决了这个问题。

Stumbled across the answer because I had the same issue with imread. 偶然发现了答案,因为我遇到了与imread相同的问题。 Issue is presented in the this thread. 问题出现在这个帖子中。 imread not working in Opencv imread在Opencv中不起作用

See the fix I found below, for mp4 files. 有关mp4文件,请参阅下面的修复程序。 I faced the same issue on Windows 7, using OpenCV 2.4.9. 我使用OpenCV 2.4.9在Windows 7上遇到了同样的问题。 I am using the java wrapper for opencv. 我正在使用opencv的java包装器。

Matthias Krings has done a lot of research for this. Matthias Krings为此做了大量研究。 See this . 看到这个 Apparently this is an issue based on the video file type. 显然这是基于视频文件类型的问题。 With .avi files, it seems to work for a lot of people. 使用.avi文件,它似乎适用于很多人。 Unfortunately his solution of setting OPENCV_DIR did not work for me. 不幸的是,他设置OPENCV_DIR的解决方案对我不起作用。 But his comments in the bug listing gave me a hint to fix the issue. 但他在错误列表中的评论给了我一个解决问题的提示。

You have to do two things: 你必须做两件事:

  1. Set java.library.path to include the directory {opencv\\install\\dir}opencv-2.4.9\\build\\x86\\vc10\\bin . 设置java.library.path以包含目录{opencv\\install\\dir}opencv-2.4.9\\build\\x86\\vc10\\bin You can set the variable using the -D option on the java command line: java -Djava.library.path=PATH_TO_YOUR_DLL ... . 您可以使用java命令行上的-D选项设置变量: java -Djava.library.path=PATH_TO_YOUR_DLL ... Also fetch this variable from your environment, using System.getProperty(...) , and print it before calling loadLibrary() , to verify that the path setting is working. 还可以使用System.getProperty(...)从您的环境中获取此变量,并在调用loadLibrary()之前将其打印出来,以验证路径设置是否正常工作。
  2. And in your java class, load the ffmpeg dll using System.loadLibrary("opencv_ffmpeg249"); 在你的java类中,使用System.loadLibrary("opencv_ffmpeg249");加载ffmpeg dll System.loadLibrary("opencv_ffmpeg249"); . The loadLibrary() function should be invoked from within a static block in java. 应该从java中的static block中调用loadLibrary()函数。
  3. There is a file named opencv_ffmpeg249.dll in the java.library.path that we set. 我们设置的java.library.path中有一个名为opencv_ffmpeg249.dll的文件。
  4. This works on ubuntu also, for .so files. 对于.so文件,这也适用于ubuntu。

在指向输入视频的正确位置后,我也遇到了同样的问题并解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM