1

I'm using VideoCapture capture(filename); to load a video from a file. When I run the program in visual studio (release mode), it works just fine, loading the video like I would expect. When I run outside of visual studio (by double-clicking the icon in the explorer directory) the video cannot be found and the capture device returns null, even though it's the same file and paths are hardcoded and absolute.

Any ideas?

Update: Also tried using the old CvCapture* and same error.

Update 6/19:

Here's some example code.

#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; } 

In Visual Studio running in release mode I get:

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

Running from the exe from the file system (double-clicking) I get:

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

I only compiled once, so there's only one exe in the directory... I've also tried displaying the frames in Visual Studio, so I know it's actually really reading the video when it thinks it's open.

6
  • I'm not saying I don't believe you but how exactly is the path hard-coded and absolute? Commented Jun 18, 2012 at 17:12
  • Hard-coded, as in not passed as a run-time argument, but written into the exe at compile time. Absolute, as in starting with the drive and not relative to the running directory. Commented Jun 18, 2012 at 17:15
  • A nice experiment to try would be to use run FILE * myFile = fopen(filename, "r"); std::cout<< myFile; fclose(myFile); to be sure you can reach the file at all. Commented Jun 18, 2012 at 17:25
  • Lol I know what the terms mean I meant perhaps show some code or a better description of any run-time error in case you overlooked something. Commented Jun 18, 2012 at 17:27
  • One guess is to check compiler output to see if youre running the latest exe and not an older build from somewhere else. Commented Jun 18, 2012 at 17:29

2 Answers 2

1

Check if all the DLL's that are required are in the same folder as your exe (or in PATH)

Sign up to request clarification or add additional context in comments.

1 Comment

Copied ALL of the OpenCV dlls into the same directory as the exe. No luck.
1

Make sure that you use absolute video path (if not, Try to copy video into exe path) and if you are using release mode, all dlls must be in the release mode. Maybe I will solve this problem if you send me a small project.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.