赞
踩
源码版本:GitHub - opencv/opencv at 4.5.5
目录
mac版本:macOS Big Sur Apple M1
安装地址 :(Java Download | Java 8, Java 11, Java 13 - Linux, Windows & macOS)
注意:Architecture类型一定要选择正确,不然使用会报下面的错,这是因为mac系统是基于ARM64,而安装java是x86 x64
- Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/local/Celler/opencv4.5.3/share/java/opencv4/libopencv_java455.dylib: dlopen(/usr/local/Celler/opencv4.5.3/share/java/opencv4/libopencv_java455.dylib, 1): no suitable image found. Did find:
- /usr/local/Celler/opencv4.5.3/share/java/opencv4/libopencv_java455.dylib: mach-o, but wrong architecture
- /usr/local/Celler/opencv4.5.3/share/java/opencv4/libopencv_java455.dylib: mach-o, but wrong architecture
需要配置JAVA_HOME,可以通过echo $JAVA_HOME进行检测
安装ant
使用brew安装:brew install ant使用brew安装:brew install cmake
- #源码下新建build文件夹,进入文件夹
- mkdir build
- cd bulid
- cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=安装路径 -DBUILD_EXAMPLES=ON ../
- make -j8
- make install
执行CMKE命令后检查java相关的是yes,否则需要检查ant,java环境配置,不是yes不会生成java相关依赖
安装后安装目录下 ./share/java/opencv4有你需要的两个包:
opencv-455.jar、libopencv_java455.dylib
Linux版本:x86_64 GNU/Linux
基于源码编译安装CMAKE(3.1-3.21)
源码: Download | CMake
- cd CMake
- ./bootstrap
- make && make install
可能遇到下面问题
- gmake: `cmake' is up to date.
- loading initial cache file /home/croot/opencv/CMake/Bootstrap.cmk/InitialCacheFlags.cmake
- -- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)
- CMake Error at Utilities/cmcurl/CMakeLists.txt:562 (message):
- Could not find OpenSSL. Install an OpenSSL development package or
- configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.
需要安装OpenSSL ,设置OPENSSL_ROOT_DIR,OPENSSL_INCLUDE_DIR为环境变量
- #源码下新建build文件夹,进入文件夹
- mkdir build
- cd bulid
- cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=安装路径 -DBUILD_EXAMPLES=ON ../
- make -j8
- make install
安装后安装目录下 ./share/java/opencv4有你需要的两个包:
opencv-455.jar、libopencv_java455.so
win10版本 x86_64
安装JAVA,配置JAVA_HOME
MinGw64一定要安装 x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z (https://nchc.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z),安装其他版本,编译库时出现没有#include<mutex> 报错的问题.之后记得配置环境变量:配置bin目录下即可
1 打开cmark-gui ,选择上面选项,完成,进入编译
2 调整参数:BUILD_SHARED_LIBS 不勾选
3 点击Configure
可能出现错误:下载文件失败
- FFMPEG: Download: opencv_videoio_ffmpeg.dll
- Try 1 failed
- CMake Warning at cmake/OpenCVDownload.cmake:202 (message):
- FFMPEG: Download failed: 28;"Timeout was reached"
-
- For details please refer to the download log file:
-
- D:/projects/java/github/opencv-4.5.4/build/CMakeDownloadLog.txt
-
- 解决方案:
- 查看CMakeDownloadLog.txt文件,
- 可以找到类似下面内容:cmake_download "D:/projects/java/github/opencv-4.5.4/.cache/ffmpeg/878a4e8fe5a4d68f18c9cdde543b9ead-opencv_videoio_ffmpeg_64.dll""https://raw.githubusercontent.com/opencv/opencv_3rdparty/40b4666d1aa374205fd61373496e15d92ecd5313/ffmpeg/opencv_videoio_ffmpeg_64.dll"
-
- 找到下载地址,通过迅雷等工具下载下载.保存到 源代码目录下的.cache目录下.命名按md4-文件名.后缀来(例如878a4e8fe5a4d68f18c9cdde543b9ead-opencv_videoio_ffmpeg_64.dll),如果遇到cmake文件,无法下载,可以在浏览器右键保存后进行修改,直接复制内容会导致md5校验失败
4 执行 mingw32-make -j 8
5 执行 mingw32-make install
6 java依赖和链接库位置: .\opencv-4.5.5\build\install\java
mvn install:install-file -Dfile=./opencv-455.jar -DgroupId=org.bytedeco -DartifactId=opencv -Dversion=4.5.5 -Dpackaging=jar
- public class TestOpencv4 {
- static {
- //System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 需要指定VM启动参数-Djava.library.path=you_path/libopencv_java455.dylib
- System.load("you_path/libopencv_java455.dylib");
- }
- public static void main(String[] args) {
- System.out.println("ok");
- }
- }
执行展示ok说明搭建完成
动态库下载链接:
基于mac m1的动态链接库:libopencv_java455.dylib-互联网文档类资源-CSDN下载
基于Linux X86X64链接库:libopencv_java455.soopencv4.5.5linux编译_Linuxjavaopencv.so-互联网文档类资源-CSDN下载
基于window10 x86_64链接库:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。