OpenCV 到 JNI 如何使其工作?
我尝试使用 opencv 和 java 进行人脸检测,在这个目的中我发现了这个“JNI2OPENCV”文件....但我对如何使其工作感到困惑,有人可以帮助我吗?
http://img519.imageshack.us/img519/4803/askaj.jpg
下面是 FaceDetection.java
class JNIOpenCV {
static {
System.loadLibrary("JNI2OpenCV");
}
public native int[] detectFace(int minFaceWidth, int minFaceHeight, String cascade, String filename);
}
public class FaceDetection {
private JNIOpenCV myJNIOpenCV;
private FaceDetection myFaceDetection;
public FaceDetection() {
myJNIOpenCV = new JNIOpenCV();
String filename = "lena.jpg";
String cascade = "haarcascade_frontalface_alt.xml";
int[] detectedFaces = myJNIOpenCV.detectFace(40, 40, cascade, filename);
int numFaces = detectedFaces.length / 4;
System.out.println("numFaces = " + numFaces);
for (int i = 0; i < numFaces; i++) {
System.out.println("Face " + i + ": " + detectedFaces[4 * i + 0] + " " + detectedFaces[4 * i + 1] + " " + detectedFaces[4 * i + 2] + " " + detectedFaces[4 * i + 3]);
}
}
public static void main(String args[]) {
FaceDetection myFaceDetection = new FaceDetection();
}
}
谁能告诉我如何在 Netbeans 上实现此功能?我尝试过谷歌,但对这个特定主题的帮助非常少。
我已将整个文件夹添加为 Netbeans 项目中的 Llibrary,当我尝试运行该文件时,我收到以下错误消息。
线程“main”中出现异常 java.lang.UnsatisfiedLinkError: FaceDetection.JNIOpenCV.detectFace(IILjava/lang/String;Ljava/lang/String;)[I 在 FaceDetection.JNIOpenCV.detectFace(本机方法) 在 FaceDetection.FaceDetection.
谁能告诉我具体的使用方法吗?就像我必须做的那样?
I am tring to use opencv and java for face detection, and in that pursit i found this "JNI2OPENCV" file....but i am confused on how to make it work, can anyone help me?
http://img519.imageshack.us/img519/4803/askaj.jpg
and the following is the FaceDetection.java
class JNIOpenCV {
static {
System.loadLibrary("JNI2OpenCV");
}
public native int[] detectFace(int minFaceWidth, int minFaceHeight, String cascade, String filename);
}
public class FaceDetection {
private JNIOpenCV myJNIOpenCV;
private FaceDetection myFaceDetection;
public FaceDetection() {
myJNIOpenCV = new JNIOpenCV();
String filename = "lena.jpg";
String cascade = "haarcascade_frontalface_alt.xml";
int[] detectedFaces = myJNIOpenCV.detectFace(40, 40, cascade, filename);
int numFaces = detectedFaces.length / 4;
System.out.println("numFaces = " + numFaces);
for (int i = 0; i < numFaces; i++) {
System.out.println("Face " + i + ": " + detectedFaces[4 * i + 0] + " " + detectedFaces[4 * i + 1] + " " + detectedFaces[4 * i + 2] + " " + detectedFaces[4 * i + 3]);
}
}
public static void main(String args[]) {
FaceDetection myFaceDetection = new FaceDetection();
}
}
CAn anyone tell me how can i make this work on Netbeans?? I tried Google but help on this particular topic is very meger.
I have added the whole folder as Llibrary in netbeans project and whe i try to run the file i get the followig wrroes.
Exception in thread "main" java.lang.UnsatisfiedLinkError: FaceDetection.JNIOpenCV.detectFace(IILjava/lang/String;Ljava/lang/String;)[I
at FaceDetection.JNIOpenCV.detectFace(Native Method)
at FaceDetection.FaceDetection.<init>(FaceDetection.java:19)
at FaceDetection.FaceDetection.main(FaceDetection.java:29)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
CAn anyone tell me the exact way to work with this? like what all i have to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在 Windows 上使用 JNI,Dependency Walker 将成为您的朋友。
但是,在我们开始之前,首先通过添加以下内容来验证 JRE 是否可以找到您的 JNIOpenCV.dll:
System.out.println("java.library.path="+System.getProperty("java.library.path"));
到静态构造函数块。
但是,我认为这里的问题不是找到您的 JNIOpenCV.dll 文件,而是找到它所依赖的文件。在依赖项步行器中打开 .dll(只需将其拖到那里)并查找任何错误消息(除了 msjava.dll - 忽略它,这并不重要)。我的预感很可能是您需要 Microsoft Visual C/C++ 运行时库,从 Visual Studio 网站下载它们并将它们放在与您的 dll 相同的文件夹中。
祝你好运!
If you are using JNI on Windows, Dependency Walker is going to be your friend.
But, before we get to that first verify that the JRE can find your JNIOpenCV.dll by adding:
System.out.println("java.library.path="+System.getProperty("java.library.path"));
to the static constructor block.
However, I think the issue here isn't finding your JNIOpenCV.dll file, but a file that it depends on. Open your .dll in dependency walker (just drag it in there) and look out for any error messages (except msjava.dll - ignore that, it doesn't matter). Most likely my hunch is that you need the Microsoft Visual C/C++ runtime libraries, download them from the Visual Studio website and put them in the same folder as your dll.
Best of luck!
你应该看一下这里,一些示例与 JNI 连接:
http:// /code.google.com/p/android-opencv/
You should take a look here, a few of the examples are hooked up with JNI:
http://code.google.com/p/android-opencv/
我使用 OpenCV 2.3.1 和 Eclipse 而不是 Netbeans 创建了一个工作 Android 示例。
这个小教程描述了一个跟随火炬光的机器人。该页面包含必要的步骤和源代码。
I have created a working Android example using OpenCV 2.3.1 and Eclipse instead of Netbeans.
This small tutorial describes a robot following torchlight. The page contains the necessary steps and the source code as well.