简体   繁体   English

在Java中使用OpenCV和JavaCV

[英]Using OpenCV in Java with JavaCV

I am getting desperate !! 我越来越绝望! I am trying to use OpenCV in Java , via JavaCV (JNA to wrap OpenCV for java). 我试图在Java中使用OpenCV ,通过JavaCV (JNA为java包装OpenCV)。

I am on Mac Os X 1.5. 我在Mac Os X 1.5上。

I installed OpenCV, and I can compile and run the examples included. 我安装了OpenCV,我可以编译并运行包含的示例。 So that works. 这样才行。

Now I open Eclipse , and I create a new project, as described here : http://code.google.com/p/javacv/ 现在我打开Eclipse ,然后创建一个新项目,如下所述: http//code.google.com/p/javacv/

In that new project, only one small class with a call to a opencv function (I used the sample code) : 在那个新项目中,只有一个小类调用了opencv函数(我使用了示例代码):

import static name.audet.samuel.javacv.jna.cxcore.*;
import static name.audet.samuel.javacv.jna.cv.*;
import static name.audet.samuel.javacv.jna.highgui.*;
import static name.audet.samuel.javacv.jna.cvaux.*;

public class Test {
    public static void main(String[] args) {
        IplImage image = cvLoadImage("test.png", 1);
        if (image == null) {
            System.err.println("Could not load image file.");
        } else {
            cvSmooth(image, image, CV_GAUSSIAN, 3, 0, 0, 0);
            // ...
        }
    }
}

When I run it, I have the following error : 当我运行它时,我有以下错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'cxcore': dlopen(libcxcore.dylib, 9): image not found 线程“main”中的异常java.lang.UnsatisfiedLinkError:无法加载库'cxcore':dlopen(libcxcore.dylib,9):找不到图像

Please, I need help, I looked over google for hours, I don't know where to look for anymore. 请,我需要帮助,我看了几个小时谷歌,我不知道在哪里寻找。

It turned out the SVN version was not compatible with JavaCV. 原来SVN版本与JavaCV不兼容。

I downloaded the latest official version (2.1) and compiled it and installed it, and it works. 我下载了最新的官方版本(2.1)并编译并安装它,它的工作原理。

See http://code.google.com/p/javacv/issues/detail?id=19 请参阅http://code.google.com/p/javacv/issues/detail?id=19

You need to link these two libraries: 您需要链接这两个库:

- javacpp.jar
- javacv.jar

In the JavaCV/lib-opencv/win_x86_64 you have to have files of your like: 在JavaCV / lib-opencv / win_x86_64中,您必须拥有类似的文件:

 - msvcp100.dll
 - msvcr100.dll
 - opencv_core220.dll
 - opencv_calib3d220.dll
 - ...

These DLLs have to be compiled for your platform (win 32 / win 64 / Linux / etc. 必须为您的平台编译这些DLL(win 32 / win 64 / Linux / etc.

You have to define path to your OpneCV DLL files: 您必须定义OpneCV DLL文件的路径:

-Djava.library.path=lib-opencv/win_x86_64/
- or the DLLs have to be somewhere in your system PATH of your operating system

I had looked at this problem for a while, as the OP suggests all kinds of problems start crawling out of the woodwork. 我已经看了一会儿这个问题,因为OP表明各种各样的问题开始爬出木工。 I went through a ton of StackOverflow posts to be able to come up with a relatively painless experience for setting up a OpenCV project in Java. 我经历了大量的StackOverflow帖子,能够在Java中设置OpenCV项目,获得相对轻松的体验。 I went through JavaCV and found that it did not meet my needs. 我经历了JavaCV,发现它无法满足我的需求。 I was however able to directly implement functionality referenced in OpenCV posts (C++ posts) but in the Java language when I used certain javacpp versions. 然而,当我使用某些javacpp版本时,我能够直接实现OpenCV帖子(C ++帖子)中引用的功能,但是使用Java语言。 I had a ton of compilation issues too since javacpp depends on compiled C++ libraries that must be native to the environment the user is in (something people that live in Java land love to not deal with). 我也有大量的编译问题,因为javacpp依赖于编译的C ++库,这些库必须是用户所处环境的原生(生活在Java中的人喜欢不处理)。 Anyway I was able to construct and environment with Maven. 无论如何,我能够用Maven构建和环境。 I use eclipse but this should work fine with other programming environments. 我使用eclipse但这应该适用于其他编程环境。 I put up an example project to illustrate how to start build a bootstrap project and start working. 我提出了一个示例项目来说明如何开始构建引导项目并开始工作。 The project compares 2 images, given their URLs. 该项目根据其网址比较了2张图片。 It's a equality test, wither the images are identical or not. 这是一个相等的测试,图像是否相同。 Hopefully this can help folks setup and get working in this environment and avoid the tons and tons of pitfalls that I encountered when trying to work with OpenCV in Java (I was in the exact same place as OP mentally at that time :) ). 希望这可以帮助人们设置并在这种环境中工作,避免在尝试使用Java中的OpenCV时遇到的大量陷阱(当时我和OP在精神上完全相同:))。

The example: https://github.com/darkhipo/ImgzCmp 示例: https//github.com/darkhipo/ImgzCmp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM