VideoCapture capture(filename);
을 사용하여 파일에서 비디오를로드합니다. 비주얼 스튜디오 (릴리즈 모드)에서 프로그램을 실행하면 예상대로 비디오를 로딩 할 수 있습니다. Visual Studio 외부에서 (탐색기 디렉토리의 아이콘을 두 번 클릭하여) 실행하면 비디오를 찾을 수 없으며 캡처 장치는 동일한 파일이고 경로가 하드 코드되고 절대적이더라도 null을 반환합니다.Visual Studio 외부에서 OpenCV VideoCapture가 작동하지 않습니다.
아이디어가 있으십니까?
업데이트 : 이전 CvCapture * 및 같은 오류를 사용해 보았습니다.
업데이트 6/19 :
는 여기에 몇 가지 예제 코드입니다. 릴리스 모드에서 실행되는 Visual Studio에서
#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;
}
내가 얻을 :
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에서 프레임을 표시하려고 했으므로 실제로 비디오가 열려 있다고 생각하면 실제로 비디오를 읽는 것입니다.
나는 당신을 믿지 않는다고 말하는 것이 아니라 경로가 정확히 어떻게 하드 코딩되고 절대적입니까? – AJG85
런타임에 인수로 전달되지 않았지만 컴파일 타임에 exe에 기록되는 것처럼 하드 코딩됩니다. 드라이브로 시작하고 실행중인 디렉토리와 관련이없는 것처럼 절대적입니다. – Jason
시도해 볼만한 좋은 실험은 run FILE * myFile = fopen (filename, "r"); std :: cout << myFile; fclose (myFile); 파일에 도달 할 수 있는지 확인하십시오. – Steve