OPENCV源码编译生成java依赖及遇到问题

OPENCV源码编译生成java依赖及遇到问题,第1张

OPENCV源码编译生成java依赖及遇到问题

源码版本:GitHub - opencv/opencv at 4.5.5

目录

一、MAC系统下编译

1 环境准备:

安装opencv4.5.5  

二、Linux系统下编译

1  环境准备

2   安装 OPENCV4.5.5                       

三、检验编译是否正确


一、MAC系统下编译

mac版本:macOS Big Sur Apple M1

1 环境准备:
  • (1)安装java环境

             安装地址 :(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
  • 安装cmake

         使用brew安装:brew install cmake

2  安装opencv4.5.5  
#源码下新建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系统下编译

Linux版本:x86_64 GNU/Linux

1  环境准备
  • 安装JAVA,配置JAVA_HOME
  • 安装ANT
  • 安装CMAKE

        基于源码编译安装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为环境变量

2   安装 OPENCV4.5.5                       
#源码下新建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

三、检验编译是否正确
  •       安装opencv-455.jar到本地仓库
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说明搭建完成

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5686018.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存