Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV Java binds VideoCapture from file failing silently

I'm using OpenCV 2.4.8 with the supplied Windows 64bit Java jar. I've been making full use of OpenCV in my current environment up until this point.

I'm unable to open video files using the VideoCapture class however webcam feeds work just fine.

The below works as expected with video.isOpened returning true

    VideoCapture video = new VideoCapture();
    boolean result = video.open(0);

The below fails with video.isOpened returning false

    VideoCapture video = new VideoCapture();
    boolean result = video.open("res/hand-test-1.mp4");

Neither file formats seems to make a difference (These are converted, not just renamed in hope)

    video.open("res/hand-test-1.mp4");
    video.open("res/hand-test-1.avi");
    video.open("res/hand-test-1.wmv");

Location seems to matter not either.

    video.open("C:/hand-test-1.mp4");
    video.open("C:\\hand-test-1.mp4");
    video.open("hand-test-1.mp4");

Neither does garbage, no exception kicked up from OpenCV through Java either, seems to fail silently.

    video.open("ashdkfhkajsjdfkhaksdf");

PATH contains the ffmpeg directory supplied with the opencv installation,

    C:\dev\opencv\sources\3rdparty\ffmpeg

Right now I've run out of ideas, it seems like whatever I throw to the native via video.open(String) will return false.

Any help would be much appreciated

like image 760
LCartwright Avatar asked Apr 21 '14 14:04

LCartwright


2 Answers

I had the same problem with OpenCV 2.4.9. The solution that fixed things lied in setting the PATH variable to the "bin" directory of the OpenCV installation directory, for example "C:\opencv\build\x64\vc11\bin".

like image 114
Alexander Avatar answered Oct 12 '22 13:10

Alexander


I had the same problem (also 2.4.9). I solved it by copying the opencv.dll to the bin folder and linking to it through eclipse. This can be done by:

  1. copy opencv_java249.dll found in /opencv/build/java/x64 to /opencv/build/x64/vc12/bin

  2. In eclipse right click on the project -> properties -> Java Build Path -> Libraries. Opencv should be listed, if not add it through Add external JARs. (opencv-249.jar and can be found at /opencv/build/java).

  3. Click on opencv-249.jar -> Native Library Location -> Edit

  4. Now navigate to /opencv/build/x64/vc12/bin and save.

OpenCV should now be able to open the files.

like image 24
Tomnar Avatar answered Oct 12 '22 14:10

Tomnar