gpt4 book ai didi

c++ - OpenCV VideoCapture 不能在 Visual Studio 之外工作

转载 作者:太空宇宙 更新时间:2023-11-03 22:34:34 25 4
gpt4 key购买 nike

我正在使用 VideoCapture capture(filename); 从文件加载视频。当我在 visual studio( Release模式)中运行该程序时,它工作得很好,像我期望的那样加载视频。当我在 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;
}

在以 Release模式运行的 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 中显示帧,所以我知道它在认为视频打开时实际上是在阅读视频。

最佳答案

检查是否所有需要的 DLL 都在与您的 exe 相同的文件夹中(或在 PATH 中)

关于c++ - OpenCV VideoCapture 不能在 Visual Studio 之外工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11087644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com