在Linux中加载OpenCV库? [英] Loading OpenCV library in Linux?

查看:1233
本文介绍了在Linux中加载OpenCV库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在Windows上构建了一个视觉库,我在Windows上运行它并且运行正常。我使用了命令:

So I built a vision library on windows, and I've ran it on Windows and it ran okay. I used the command:

java -jar LiftTracker.jar

我将我在windows上构建的.jar文件传输到Raspberry Pi,并进行了make install以安装opencv库。一旦我这样做,我尝试执行与上面相同的命令并提出错误:

I transferred the .jar file I built on windows over to a Raspberry Pi, and did a make install to install the opencv libraries. Once I did that, I tried to do the same command as above and came up with the error:

java.lang.UnsatisfiedLinkError: no opencv_java310 in java.library.path.

我做了一些研究,发现我可以在-jar命令旁边运行这个命令

I did some research and found that I could run this command along side the -jar command

java -Djava.library.path=/path/to/dir

这仍然不起作用。这是我导入系统库的方式吗?我在代码中导入它的方式是:

That still did not work. Is it the way that I am importing the system library? The way I'm importing it in the code is by:

static{ 

    System.loadLibrary("opencv_java310");

}

我认为它不起作用的主要原因是因为我安装opencv的方式。有什么想法吗?

I think the main reason that it's not working is because of the way I installed opencv. Any ideas?

谢谢!

推荐答案

你需要添加 libopencv_java320.so到你的java项目库。它大约是1mb的额外库。

You need to add "libopencv_java320.so" to your java project libs. It is around 1mb additional library.


  1. 您可以根据文档从源生成此.so文件: https ://opencv-java-tutorials.readthedocs.io/en/latest/01-installing-opencv-for-java.html#install-opencv-3-x-under-linux

另一种方法是使用终端cmake手动构建源代码(它将下载大约4gb的opencv源代码),应该很简单:从opencv下载源代码: http://opencv.org/releases.html 解压缩并在解压缩的目录中创建一个这样的/ build目录../opencv- 3.2.0 /编译/。确保安装了cmake(Debian / Ubuntu apt get install cmake )。在先前创建的/ build文件夹中打开终端并键入: cmake -DBUILD_SHARED_LIBS = OFF .. 操作完成后输入 make -j8 之后应为3.2.0版本生成libopencv_java_320 - 将此.so复制到您的java项目中。最后一个类型 make install 从同一个构建目录在系统上安装3.2.0库(如果需要,您可能希望先前删除旧版本)。更多信息: https://elbauldelprogramador.com/en /compile-opencv-3.2-with-java-intellij-idea/

another way is to build sources manually using terminal cmake (it will download around 4gb of opencv sources), should be easy: download the source from opencv: http://opencv.org/releases.html Unzip it and inside unpacked directory create a /build directory like this ../opencv-3.2.0/build/. Make sure you have cmake installed (Debian/Ubuntu apt get install cmake). Open terminal in previously created /build folder and type: cmake -DBUILD_SHARED_LIBS=OFF .. after operation finishes type make -j8 and after that "libopencv_java_320" should be generated for 3.2.0 version - copy this .so into your java project. Last type make install from the same build directory to install 3.2.0 libs on the system (you might want to previously remove older version if necessary). More info here: https://elbauldelprogramador.com/en/compile-opencv-3.2-with-java-intellij-idea/

与上述方法相同,但自动化将使用此脚本: https://github.com/milq/milq/ blob / master / scripts / bash / install-opencv.sh 脚本还在linux系统上安装opencv。从这个来源获取它: http://milq.github.io/install-opencv -ubuntu-debian / 它比第二种方法做得更多,应该最容易制作。

same as above approach but automated will be by using this script: https://github.com/milq/milq/blob/master/scripts/bash/install-opencv.sh Script does also install opencv on the linux system. Took it from this source: http://milq.github.io/install-opencv-ubuntu-debian/ It does much more then 2nd approach, should be easiest to make.

在系统中安装opencv libs并将libopencv_java320.so复制到你的java项目后,你可以删除源代码(毕竟它几乎是4GB)。

After installing opencv libs in system and copying libopencv_java320.so into your java project you can remove sources (it is almost 4gb after all).

然后你可以使用下面的代码您的主要方法加载Windows .dll(如果您之前也添加了它)和linux .so:

Then you can use below code in your main method to load windows .dll (if you previously added it too) and linux .so:

String libName = "";
if (SystemUtils.IS_OS_WINDOWS) {
    libName = "opencv_java320.dll";
} else if (SystemUtils.IS_OS_LINUX) {
    libName = "libopencv_java320.so";
}
System.load(new File("./libs/".concat(libName)).getAbsolutePath());

这篇关于在Linux中加载OpenCV库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆