2012-06-18 124 views
1

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

任何想法?

更新:也尝试使用旧的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中显示帧,所以我知道它实际上是在它认为它打开时阅读视频。

+0

我不是说我不相信你,但硬编码和绝对路径的确切程度如何? – AJG85

+0

硬编码,因为不作为运行时参数传递,但在编译时写入exe。绝对的,如在开始与驱动器,而不是相对于运行目录。 – Jason

+0

一个很好的尝试就是使用运行FILE * myFile = fopen(filename,“r”); std :: cout << myFile; FCLOSE(MYFILE);确保你可以到达文件。 – Steve

回答

1

检查所有需要的DLL的是在同一文件夹作为您的exe文件(或PATH)

+0

将所有OpenCV dll复制到与exe相同的目录中。没有运气。 – Jason

1

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

+0

新增示例代码 – Jason

相关问题