How To Install OpenCV 3.3+ with Java on Mac
If after installing OpenCV on Mac via brew, such as by using
brew install opencv
Then you may be getting an error when trying to use `System.loadLibrary(Core.NATIVE_LIBRARY_NAME)` that says something like:
UnsatisfiedLinkError: no opencv_java331 in java.library.path
The solution to this is to reinstall OpenCV with the proper Java libs. Try the following steps:
brew install ant
brew edit opencv
# change -DBUILD_opencv_java=OFF to ON
brew uninstall opencv # if you installed opencv before
brew install --build-from-source opencv # Note: this may take a long time
You may also need to point your IDE to the Java lib location by using a JVM arg such as:
-Djava.library.path=/usr/local/Cellar/opencv3/XXX/share/OpenCV/java
Check out my other blog posts! If you found this post interesting, feel free to let me know either on Twitter (@Isaac_M_Jordan), or in the comments section below.
Enjoyed my post? Sign up to the newsletter to receive a small email when I post. No spam, I promise.
-
Guy T on Feb. 4, 2020, 12:01 a.m.
I have the exact same error. Cmake is failing to build it
-
Guy T on Feb. 4, 2020, 12:03 a.m.
And at the exact same phase to [26%]
-
Sharon on June 2, 2020, 2:38 a.m.
I have the same problem, could you tell me how you fix it?
-
-
MHD on March 21, 2022, 5:36 p.m.
I did everything as it says here, but I have "java" folder nowhere
Roberto on Jan. 23, 2020, 9:51 a.m.
I have followed the steps indicated in the tutorial:
1º I installed xcode.
2º I installed homebrew
3º xcode-select --install
4º brew install ant
5º brew edit opencv and I have modified -DBUILD_opencv_java = OFF by -DBUILD_opencv_java = ON
To finish brew install --build-from-source opencv. I get the following error:
==> Downloading https://github.com/opencv/opencv/archive/4.2.0.tar.gz
==> Downloading https://github.com/opencv/opencv_contrib/archive/4.2.0.tar.gz
Already downloaded:
==> cmake .. -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG
==> make
Last 15 lines from /Users/robertodaza/Library/Logs/Homebrew/opencv/02.make:
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: ../lib/liblibprotobuf.a(gzip_stream.cc.o) has no symbols
/usr/bin/ranlib ../lib/liblibprotobuf.a
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: ../lib/liblibprotobuf.a(arenastring.cc.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: ../lib/liblibprotobuf.a(io_win32.cc.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: ../lib/liblibprotobuf.a(gzip_stream.cc.o) has no symbols
[ 26%] Built target libprotobuf
[ 26%] Linking CXX static library ../../../../../../lib/libmultiview.a
cd /tmp/opencv-20200119-31308-zryaly/opencv-4.2.0/build/modules/sfm/src/libmv/libmv/multiview && /usr/local/Cellar/cmake/3.16.2/bin/cmake -P CMakeFiles/multiview.dir/cmake_clean_target.cmake
cd /tmp/opencv-20200119-31308-zryaly/opencv-4.2.0/build/modules/sfm/src/libmv/libmv/multiview && /usr/local/Cellar/cmake/3.16.2/bin/cmake -E cmake_link_script CMakeFiles/multiview.dir/link.txt --verbose=1
/usr/bin/ar qc ../../../../../../lib/libmultiview.a CMakeFiles/multiview.dir/conditioning.cc.o CMakeFiles/multiview.dir/euclidean_resection.cc.o CMakeFiles/multiview.dir/fundamental.cc.o CMakeFiles/multiview.dir/fundamental_kernel.cc.o CMakeFiles/multiview.dir/homography.cc.o CMakeFiles/multiview.dir/panography.cc.o CMakeFiles/multiview.dir/panography_kernel.cc.o CMakeFiles/multiview.dir/projection.cc.o CMakeFiles/multiview.dir/robust_estimation.cc.o CMakeFiles/multiview.dir/robust_fundamental.cc.o CMakeFiles/multiview.dir/robust_resection.cc.o CMakeFiles/multiview.dir/triangulation.cc.o CMakeFiles/multiview.dir/twoviewtriangulation.cc.o
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: ../../../../../../lib/libmultiview.a(robust_estimation.cc.o) has no symbols
/usr/bin/ranlib ../../../../../../lib/libmultiview.a
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: ../../../../../../lib/libmultiview.a(robust_estimation.cc.o) has no symbols
[ 26%] Built target multiview make: *** [all] Error 2
What can I do to fix this?
I will be grateful for any help you can provide.