美文网首页js css html
Macbook M1 编译安装 OpenCV 及配置 IDEA

Macbook M1 编译安装 OpenCV 及配置 IDEA

作者: iVikings | 来源:发表于2024-03-12 16:22 被阅读0次
    • 下载 opencv 源码
    brew install wget
    
    wget -O opencv.zip https://github.com/opencv/opencv/archive/4.8.0.zip
    
    wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.8.0.zip
    
    unzip opencv.zip
    unzip opencv_contrib.zip
    
    • 编译安装
      进入下载路径,并创建 build 文件夹
    cd opencv-4.8.0
    
    mkdir build && cd build
    

    build 文件夹 下新建 run.sh,并输入如下代码,其中BUILD_opencv_java设置为ONOPENCV_EXTRA_MODULES_PATH 设置为下载的 opencv_contribmodules 路径

    set -ex
    
    cmake \
    -DCMAKE_SYSTEM_PROCESSOR=arm64 \
    -DCMAKE_OSX_ARCHITECTURES=arm64 \
    -DWITH_OPENJPEG=OFF \
    -DWITH_IPP=OFF \
    -DCMAKE_BUILD_TYPE=RELEASE \
    -DCMAKE_INSTALL_PREFIX=/usr/local/opencv \
    -DJAVA_INCLUDE_PATH=/Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home/include \
    -DJAVA_AWT_INCLUDE_PATH=/Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home/include \
    -DJAVA_INCLUDE_PATH2=/Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home/include/darwin \
    -DBUILD_opencv_python2=OFF \
    -DBUILD_opencv_java=ON \
    -DINSTALL_PYTHON_EXAMPLES=OFF \
    -DINSTALL_C_EXAMPLES=OFF \
    -DBUILD_ZLIB=OFF \
    -DOPENCV_ENABLE_NONFREE=ON \
    -DOPENCV_EXTRA_MODULES_PATH=/Users/huipeng/Desktop/AIGC/opencv/opencv_contrib-4.8.0/modules \
    -DBUILD_EXAMPLES=ON ..
    

    输入 bash run.sh 运行该命令,成功后输出:

    --   OpenCL:                        YES (no extra features)
    --     Include path:                NO
    --     Link libraries:              -framework OpenCL
    --
    --   Python (for build):            /opt/homebrew/bin/python3
    --
    --   Java:
    --     ant:                         NO
    --     Java:                        YES (ver 1.8.0.381)
    --     JNI:                         /Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home/include /Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home/include/darwin /Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home/include
    --     Java wrappers:               YES (JAVA)
    --     Java tests:                  NO
    --
    --   Install to:                    /usr/local/opencv
    -- -----------------------------------------------------------------
    --
    -- Configuring done (102.5s)
    -- Generating done (3.4s)
    -- Build files have been written to: /Users/huipeng/Desktop/AIGC/opencv/opencv-4.8.0/build
    

    然后输入如下指令编译:

    make -j8
    

    最后输入如下指令安装:

    sudo make install
    

    完成之后会在两个地方出现jar文件和lib文件,一个是build路径

    opencv-4.8.0/build/bin/opencv-480.jar
    opencv-4.8.0/build/lib/libopencv_java480.dylib
    

    一个是安装路径:

    /usr/local/opencv/share/java/opencv4/libopencv_java480.dylib
    /usr/local/opencv/share/java/opencv4/opencv-480.jar 
    
    • 设置 Java Library Path:
    -Djava.library.path=/usr/local/opencv/share/java/opencv4
    
    • 设置 Libraries

    参考:https://blog.csdn.net/qq_39567427/article/details/131890490

    相关文章

      网友评论

        本文标题:Macbook M1 编译安装 OpenCV 及配置 IDEA

        本文链接:https://www.haomeiwen.com/subject/adavzdtx.html