OpenCV VideoCapture无法在Visual Studio外部工作

时间:2012-06-18 17:04:54

标签: c++ visual-studio-2008 video opencv

我正在使用VideoCapture capture(filename);从文件加载视频。当我在visual studio(发布模式)中运行程序时,它工作得很好,像我期望的那样加载视频。当我在visual studio外面运行时(通过双击explorer目录中的图标),无法找到视频,捕获设备返回null,即使它是相同的文件,路径是硬编码和绝对的。

有什么想法吗?

更新:还尝试使用旧的CvCapture *和同样的错误。

更新6/19:

这是一些示例代码。

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** args)
{
    const char* filename = "c:/testvideo.wmv";

    //Check to see if we can see the file
    FILE* myFile = fopen(filename, "r");
    if (myFile)
        cout<<"0: Found file"<<endl;
    else
        cout<<"0: File not found"<<endl;

    //First use the openCV new way of doing it
    VideoCapture capture1(filename);

    if (capture1.isOpened())
        cout<<"1: Opened the video successfully"<<endl;
    else
        cout<<"1: Could not open the video"<<endl;

    //Second, try the old way
    CvCapture* capture2 = cvCaptureFromFile(filename);
    if (capture2)
        cout<<"2: Opened the video successfully"<<endl;
    else
        cout<<"2: Could not open the video"<<endl;

    //Pause
    char c;
    cin>>c;

    return 0;
}

在以发布模式运行的Visual Studio中,我得到:

0: File Found
1: Opened the video successfully
2: Opened the video successfully

从文件系统的exe(双击)运行,我得到:

0: File Found
1: Could not open the video
2: Could not open the video

我只编译了一次,所以目录中只有一个exe ... 我也尝试在Visual Studio中显示帧,所以我知道它实际上是在视频打开时正在阅读。

2 个答案:

答案 0 :(得分:1)

检查所需的所有DLL是否与exe(或PATH)位于同一文件夹中

答案 1 :(得分:1)

确保使用绝对视频路径(如果没有,尝试将视频复制到exe路径中),如果使用的是发布模式,则所有dll必须处于发布模式。如果你给我发一个小项目,也许我会解决这个问题。

相关问题