我正在使用VideoCapture capture(filename);
从文件中加载视频。当我在 Visual Studio(发布模式)中运行该程序时,它工作得很好,可以像我期望的那样加载视频。当我在 Visual Studio 之外运行时(通过双击资源管理器目录中的图标),找不到视频并且捕获设备返回 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...