0

I wanted to use Open CV in my project and followed below installation process:

http://opencv-java-tutorials.readthedocs.io/en/latest/01-installing-opencv-for-java.html#install-opencv-3-x-under-macos

I was not able to get Java folder in the installed directory. As I was getting below error on my Java code:

"NATIVE_LIBRARY_NAME cannot be resolved"

I tried few things till now -

  1. I did "brew edit opencv" and changed "-DBUILD_opencv_java=OFF" to "ON" and did "brew reinstall opencv --with-java"

  2. I tried adding external jar and tried changing the native library location but no help as there is no java folder available in opencv directory

I am not getting help from any source.

Virat Mishra
  • 155
  • 1
  • 2
  • 9

2 Answers2

0

For build OpenCV with java libraries you should make project with parametr

cmake -D BUILD_SHARED_LIBS=OFF

After configure project you should see java in OpenCV modules

--   OpenCV modules:
--     To be built: ... java ...

And

--   Java:
--     ant:                         /usr/bin/ant (ver 1.10.1)
--     JNI:                         /usr/lib/jvm/java/include /usr/lib/jvm/java/include/linux /usr/lib/jvm/java/include
--     Java wrappers:               YES
--     Java tests:                  YES

If you build project with this parametrs, but didn't see java in OpenCV modules then try set JAVA_HOME environment For linux

export JAVA_HOME=<path_to_jdk>

For windows

set JAVA_HOME=<path_to_jdk>

I builded OpenCV project with command below:

cmake -D CMAKE_BUILD_TYPE=RELEASE 
    -D CMAKE_INSTALL_PREFIX=/usr/local 
    -D BUILD_OPENCV_JAVA=ON
    -D BUILD_SHARED_LIBS=OFF
    -D WITH_IPP=ON 
    -D WITH_TBB=ON
    -D IPP_H_PATH=/opt/intel/ipp/include/ ..

Parametrs WITH_IPP and WITH_TBB provide multithreading.

After make install phase you can see jar library in ../bin and /usr/[local/]share/OpenCV

Related resources:

1) Oficial site

2) Man for Linux install process

3) Add OpenCV to Eclipse project

Mikro Koder
  • 1,056
  • 10
  • 13
  • I am trying to install openCV with java on MACOS exactly following the procedure but everytime there is no JAVA folder! Please help – Swapnil B May 14 '20 at 11:24
0

For those who didn't know how to save the change of arg

DBUILD_opencv_java=OFF

to

DBUILD_opencv_java=ON

Such file exist on :

/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/opencv.rb

So open it with any text editor and save it easily.

Marwan Mostafa
  • 403
  • 4
  • 12