Ask Your Question
1

opencv3 videoCapture doesn't work

asked 2015-08-31 14:42:35 -0600

jma gravatar image

I've a problem with openCV 3 java wrapper.

When i use videocapture, camera.grab() always return false. I see several subjects on internet about this problem. I succeeded to run opencv 2.4 but not with version 3.

My environnement :

  • windows 10 (64b)
  • java 8u51 (32b)
  • eclipse mars (32b)

So, I test these methods. Env :

  • Set windows path : D:\Programs\opencv3x\build\x86\vc12\bin
  • Add opencv_ffmpeg to D:\Programs\opencv3x\build\x86\vc12\bin (in opencv 3, this lib is already in with the good name : opencv_ffmpeg300.dll).

Dev env : In eclipse project :

  • add opencv-300.jar
  • set the native lib to D:/Programs/opencv3x/build/java/x86
  • With this configuration, I can use opencv 3 without problem...but i can't decode video file!

Does anyone have a solution on this? Thx.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2015-09-20 10:22:49 -0600

RolandC gravatar image

updated 2015-09-20 10:25:00 -0600

You need to load the ffmpeg dll as well. You could create a folder structure

lib\opencv-300.jar
lib\x64\opencv_java300.dll
lib\x64\opencv_ffmpeg300_64.dll

and add the jar to your build path.

Then in your application load the libraries e. g. like this:

// set the library path during runtime (or specify it at program start via -Djava.library.path=...)
try {

    System.setProperty("java.library.path", "lib/x64");

    Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
    fieldSysPath.setAccessible(true);
    fieldSysPath.set(null, null);

} catch (Exception ex) {
    ex.printStackTrace();
    throw new RuntimeException(ex);
}

// load the required libraries
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.loadLibrary("opencv_ffmpeg300_64");

The video is now playable with

VideoCapture videoCapture = new VideoCapture();
videoCapture.open("c:/movies/mymovie.mp4");
edit flag offensive delete link more
0

answered 2017-01-13 11:07:46 -0600

Your second method will work if you remember that you use Java.

• Add opencv_ffmpeg to .../opencv3x/build/java/x86 - the path that you set for native lib in Eclipse.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-08-31 14:41:21 -0600

Seen: 3,064 times

Last updated: Jan 13 '17