VideoCapture is not working after building opencv 3.1 in Java

asked 2016-10-13 01:29:16 -0600

BAHRAMUDIN ADIL gravatar image

updated 2016-10-13 01:30:33 -0600

In the first I want to say that if I use OpenCV pre-built JAR and .dll file it works great with out any problem.

I downloaded the latest version of needed software and tools for building the OpenCV with extra modules; such as opencv 3.1.0 source, CMake 3.6.2, Python 3.6, Java 1.8, ANT 1.9.7 And Visual Studio 2015

I have completed all the steps successfully, and there was no any error happened during building. At end it generated a folder call install, inside looks like this:

image description

It has the same files and folders as the OpenCV pre-built generated folder. After that I add this ...\install\x64\vc14\bin to the System path, then in Java project when I use the VideoCapture now it doesn't work and throws an unknown exception

VideoCapture capture = new VideoCapture("...\768x576.avi");
Mat mat = new Mat();
while (capture.isOpened()) { // int this line throw an unknown exception
    capture.read(mat);
    System.out.println("mat = " + mat);
}
capture.release();

I have loaded the lib like this (it works when I use OpenCV pre-built lib):

System.setProperty("java.library.path", "...\build\install\java");
Field sys_paths = ClassLoader.class.getDeclaredField("sys_paths");
sys_paths.setAccessible(true);
sys_paths.set(null, null);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

Now What is the problem, I have tried many tutorials, build is success but this problem did not solve.

edit retag flag offensive close merge delete

Comments

when exactly your code is crashing? Is it at the moment when the capture is released or earlier?

jcrist gravatar imagejcrist ( 2016-10-17 13:19:22 -0600 )edit

I think you did not read the question carefully, if you read you will find your answer.

BAHRAMUDIN ADIL gravatar imageBAHRAMUDIN ADIL ( 2016-10-18 20:39:24 -0600 )edit

This looks like the old issue, should be already fixed in the upstream. capture.release() is not yet fixed.

jcrist gravatar imagejcrist ( 2016-11-01 09:31:17 -0600 )edit