我的系统是macOS Catalina,安装opencv步骤如下,参考文档https://blog.csdn.net/lifetragedy/article/details/123459339:
-
vi ~/.zshrc
,加入:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
export SSL_CERT_DIR="/usr/local/etc/openssl/certs"
export SSL_CERT_FILE="/usr/local/etc/openssl/cert.pem"
brew源可以选择https://mirrors.ustc.edu.cn/homebrew-bottles
或https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
- 执行
source ~/.zshrc
- 执行
brew update
- 执行
brew edit opencv
,把-DBUILD_opencv_java=OFF
修改为-DBUILD_opencv_java=ON
- 安装JAVA
brew install openjdk
,会安装java18 - 在~/.zshrc加入java18的JAVA_HOME环境变量
export JAVA_HOME=/usr/local/Cellar/openjdk/18
- 执行
brew install ant
- 执行
brew install --build-from-source opencv
可能会卡在安装依赖
==> Installing dependencies for opencv: nettle, p11-kit,....
,报错Error: No such file or directory @ rb_sysopen
解决方法:把那些依赖复制下来去掉逗号,用brew install 单独安装一次,如:
brew install nettle p11-kit libevent libnghttp2 unbound gnutls lame libass libbluray cjson cmocka mbedtls librist libsoxr libvidstab libogg libvorbis libvpx opencore-amr opus rav1e flac libsndfile libsamplerate rubberband sdl2 snappy speex srt libarchive tesseract theora x264 x265 xvid libsodium zeromq zimg ffmpeg@4 numpy protobuf boost gl2ps glew libaec hdf5 jsoncpp netcdf pugixml pyqt@5 utf8cpp vtk
然后再执行:brew install --build-from-source opencv
- 查看安装目录:
/usr/local/Cellar/opencv/4.5.5
,安装成功 - 将
/usr/local/share/java/opencv4/libopencv_java454.dylib
文件拷贝到jdk的lib目录下
网友评论