There was originally a Mac Mini and a Macbook Air, respectively using two methods of installation of OpencV environment, the following to share two environments and methods.
Opencv + Java for M1 MAC
Independent download source code compilation
This part mainly reference in barrettodexter.medium.com/setting-up-… Having arm64, need x86,x64, etc. This is probably because rossta2 has translated your JDK from a non-ARM version. Suggest to Java Download | Java 8, 11, Java Java 13 – Linux, Windows and macOS (azul.com) to Download you need ARM version of the JDK, and corresponding JDK configuration for the project in the IDEA
Borrow OpencV from Homebrew installation
There is not much introduction to the installation process of Homebrew here, but during the installation process, I used the source of Aliyun for the first time and found the problem that I could not download. Later, I switched back to the original source and found some information on the official website when I searched for OpencV in brew for the first time:
I was too young to think I just neededbrew install opencv --with-java
This is fine, but the message pops up as follows:
Try to usebrew info opencv
After the discovery
The corresponding parameters are not specified. So take a different approach and look up how BREW worksbrew edit opencv
Try querying the way JAVA is supported
Pull to the cmake parameters section to see that the default is OFF, so we change it to ON and add the JAVA compilation parameters later
-DOPENCV_JAVA_TARGET_VERSION The DOPENCV_JAVA_TARGET_VERSION is very important. The jar of the current highest version is generated and cannot be used
- 1.8 DJAVA_INCLUDE_PATH DOPENCV_JAVA_TARGET_VERSION = = / Library/Java/JavaVirtualMachines/Zulu - 8. The JDK/Contents/Home/include -DJAVA_AWT_LIBRARY=/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/libawt.dylib -DJAVA_JVM_LIBRARY=/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/libjvm.dylibCopy the code
Brew install –build-from-source Opencv is not installed, because we did not use source code to compile. Brew install –build-from-source Opencv is running, and the process is a bit long. But it’s much more comfortable than using Cmake ourselves. See familiar 🍺 logo represents success into/opt/homebrew/Cellar/opencv / 4.5.3 _1 / share/Java/opencv4 can see dylib and jar file
Compilation part completed!!
The IDEA of configuration
This part is relatively simple, first corresponding JAR package is to drink their own project, this comparison is not more detailed, the key is to configure the address of the local OpencV library in the program to start
Execute my simple demo
The results are as follows
✌ ️