I have followed countless instructions available online to install and run opencv Java on MacOS M1 arm64 architecture but not been successful.
After lot of hit and trials i did following:
brew install opencv
then
brew edit opencv //to do -DBUILD_opencv_java=ON
then copied the entire opencv.rb to a new file at another location. Followed by
brew uninstall opencv
brew reinstall /path/to/new/opencv.rb --build-from-source -v
which installs opencv correctly as I can verify with brew info opencv
which results in
brew info opencv
==> opencv: stable 4.9.0 (bottled)
Open source computer vision library
Home
Installed
/usr/local/Cellar/opencv/4.9.0_12 (974 files, 256.8MB) *
Built from source on 2024-07-04 at 10:50:47
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/o/opencv.rb
License: Apache-2.0
==> Dependencies
Build: cmake ✔, pkg-config ✔, python-setuptools ✔
Required: abseil ✔, ceres-solver ✔, eigen ✔, ffmpeg@6 ✔, freetype ✔, gflags ✔, glog ✔, harfbuzz ✔, jpeg-turbo ✔, libpng ✔, libtiff ✔, numpy ✔, openblas ✔, openexr ✔, openjpeg ✔, openvino ✔, protobuf ✔, [email protected] ✔, tbb ✔, tesseract ✔, vtk ✔, webp ✔, glew ✔, imath ✔, jsoncpp ✔, libarchive ✔
==> Analytics
install: 14,695 (30 days), 39,165 (90 days), 142,687 (365 days)
install-on-request: 13,918 (30 days), 37,238 (90 days), 133,670 (365 days)
build-error: 17 (30 days)
So I try to create a Java project, copy the two below from /usr/local/Cellar/opencv/4.9.0_12/share/java/opencv4
libopencv_java490.dylib
opencv-490.jar
into project directory and add jars and Library. Also set VM for -Djava.library.path=/usr/local/Cellar/opencv/4.9.0_12/share/java/opencv4
. But no matter what I do I always end up getting this error,
java: cannot access org.opencv.core.Core
bad class file: /path/to/src/src/opencv-490.jar!/org/opencv/core/Core.class
class file has wrong version 66.0, should be 61.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
My system is out and out Java17, i.e version & Project structure.
java --version
java 17.0.9 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 17.0.9+11-LTS-201)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.9+11-LTS-201, mixed mode, sharing)
Any idea whats going wrong here ?