Current is 2022. The brew tool and pip tool could support OpenCV-4.6 very well.
Use brew tool:
1, install java if needed
brew install openjdk
If have error message ‘No Java Runtime present,requesting to install’, we need to complete the environment path. Use ‘temurin’ to casting from the env-path.
brew install temurin
2, install ant before install the OpenCV library
brew install ant
3, install OpenCV (version 4.6.0)
By default, install opencv by brew won’t support Java, need to update the install script before build.
brew edit opencv
Find a line:
-DBUILD_opencv_java=OFF
Change to:
-DBUILD_opencv_java=ON
Then install the OpenCV
brew install --build-from-source opencv
4, verify the library. The jar and dylib files will be located at /opt/homebrew/Cellar/opencv/4.6.0_1/share/java folder
brew info opencv
tabtu@ttAir ~ % brew info opencv ==> opencv: stable 4.6.0 (bottled) Open source computer vision libraryHome/opt/homebrew/Cellar/opencv/4.6.0_1 (857 files, 123.1MB) * Built from source on 2022-11-28 at 16:36:04 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/opencv.rb License: Apache-2.0 ==> Dependencies Build: cmake ✔, pkg-config ✔ Required: ceres-solver ✔, eigen ✔, ffmpeg ✔, glog ✔, harfbuzz ✔, jpeg-turbo ✔, libpng ✔, libtiff ✔, numpy ✔, openblas ✔, openexr ✔, openjpeg ✔, protobuf ✔, python@3.10 ✔, tbb ✔, vtk ✔, webp ✔ ==> Analytics install: 13,646 (30 days), 45,632 (90 days), 193,390 (365 days) install-on-request: 13,194 (30 days), 44,222 (90 days), 186,369 (365 days) build-error: 76 (30 days)