Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

VideoCapture is not working after building opencv 3.1 in Java

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 many and many tutorials, build is success but this problem did not solve.

VideoCapture is not working after building opencv 3.1 in Java

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 many and tried many tutorials, build is success but this problem did not solve.