在 Java 中使用 OpenCV 和 JavaCV
我快绝望了!!我正在尝试通过JavaCV在Java中使用OpenCV(JNA为java包装OpenCV)。
我使用的是 Mac Os X 1.5。
我安装了 OpenCV,并且可以编译并运行其中的示例。这样就可以了。
现在我打开 Eclipse,并创建一个新项目,如下所述: http://code.google.com/p/javacv/
在该新项目中,仅一个调用 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);
// ...
}
}
}
当我运行它时,出现以下错误:
线程“main”中出现异常 java.lang.UnsatisfiedLinkError:无法 加载库“cxcore”: dlopen(libcxcore.dylib, 9): 图像不存在 找到了
,请,我需要帮助,我在谷歌上搜索了几个小时,我不知道在哪里可以再寻找。
I am getting desperate !! I am trying to use OpenCV in Java, via JavaCV (JNA to wrap OpenCV for java).
I am on Mac Os X 1.5.
I installed OpenCV, and I can compile and run the examples included. So that works.
Now I open Eclipse, and I create a new project, as described here :
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) :
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
Please, I need help, I looked over google for hours, I don't know where to look for anymore.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
结果发现SVN版本与JavaCV不兼容。
我下载了最新的官方版本(2.1)并编译安装,可以运行。
请参阅 http://code.google.com/p/javacv/issues/详情?id=19
It turned out the SVN version was not compatible with JavaCV.
I downloaded the latest official version (2.1) and compiled it and installed it, and it works.
See http://code.google.com/p/javacv/issues/detail?id=19
您需要链接这两个库:
在 JavaCV/lib-opencv/win_x86_64 中,您必须拥有您喜欢的文件:
这些 DLL 必须针对您的平台进行编译(win 32 / win 64 / Linux / 等。
您必须定义OpneCV DLL 文件的路径:
You need to link these two libraries:
In the JavaCV/lib-opencv/win_x86_64 you have to have files of your like:
These DLLs have to be compiled for your platform (win 32 / win 64 / Linux / etc.
You have to define path to your OpneCV DLL files:
我已经研究这个问题有一段时间了,正如OP建议的那样,各种各样的问题开始从木制品中爬出来。我浏览了大量 StackOverflow 帖子,以便能够获得在 Java 中设置 OpenCV 项目的相对轻松的体验。我浏览了一下JavaCV,发现它不能满足我的需求。然而,当我使用某些 javacpp 版本时,我能够直接实现 OpenCV 帖子(C++ 帖子)中引用的功能,但使用 Java 语言。我也遇到了大量的编译问题,因为 javacpp 依赖于编译的 C++ 库,这些库必须是用户所在环境的本机库(生活在 Java 土地上的人们不喜欢处理这些问题)。无论如何,我能够使用 Maven 构建和环境。我使用 eclipse 但这应该可以在其他编程环境中正常工作。我提供了一个示例项目来说明如何开始构建引导项目并开始工作。
该项目比较了 2 个图像,并给出了它们的 URL。这是一个平等测试,无论图像是否相同。希望这可以帮助人们在这个环境中进行设置和工作,并避免我在尝试使用 Java 中的 OpenCV 时遇到的大量陷阱(当时我的心理状态与 OP 完全相同:))。
示例:https://github.com/darkhipo/ImgzCmp
I had looked at this problem for a while, as the OP suggests all kinds of problems start crawling out of the woodwork. 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. I went through JavaCV and found that it did not meet my needs. 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. 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). Anyway I was able to construct and environment with Maven. I use eclipse but this should work fine with other programming environments. 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. 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 :) ).
The example: https://github.com/darkhipo/ImgzCmp