Android的,生成JNI头文件使用javah的,显示错误不能找到org.opencv.core.Mat [英] Android, generate jni Header Files with javah , show error that can't find org.opencv.core.Mat

查看:2335
本文介绍了Android的,生成JNI头文件使用javah的,显示错误不能找到org.opencv.core.Mat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是有一个恼人的问题与JNI当我编译 javah的在Java类中的本地方法生成JNI头文件。

I just have an annoying problem with jni when i compile the native method in java class with javah to generate JNI header files.

如果该类使用了第三方软件包,例如:org.opencv.core.Mat,那么 javah的将显示无法找到的错误org.opencv.core.Mat类。

If the class has used 3rd-party package, For example: org.opencv.core.Mat, then the javah will show the error that can't find the org.opencv.core.Mat class.

在OpenCV样品code如下:

The OpenCV sample code as below:

package org.opencv.samples.fd;

import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;

public class DetectionBasedTracker
{
public DetectionBasedTracker(String cascadeName, int minFaceSize) {
    mNativeObj = nativeCreateObject(cascadeName, minFaceSize);
}

public void start() {
    nativeStart(mNativeObj);
}

public void stop() {
    nativeStop(mNativeObj);
}

public void setMinFaceSize(int size) {
    nativeSetFaceSize(mNativeObj, size);
}

public void detect(Mat imageGray, MatOfRect faces) {
    nativeDetect(mNativeObj, imageGray.getNativeObjAddr(), faces.getNativeObjAddr());
}

public void release() {
    nativeDestroyObject(mNativeObj);
    mNativeObj = 0;
}

private long mNativeObj = 0;

private static native long nativeCreateObject(String cascadeName, int minFaceSize);
private static native void nativeDestroyObject(long thiz);
private static native void nativeStart(long thiz);
private static native void nativeStop(long thiz);
private static native void nativeSetFaceSize(long thiz, int size);
private static native void nativeDetect(long thiz, long inputImage, long faces);
}

首先,我使用的命令

First, I used the command

javah -classpath bin/classes -bootclasspath (the directory of android.jar) -d jni (packageName + ClassName) , shows the error "can't find the org.opencv.core.Mat

然后,我修改了命令,以

Then I modified the command to

javah - classpath bin/classes - bootclasspath (the dir of android.jar) ; (the dir of the opencv lib jar)  -d jni ..." ", this time it shows error

异常

Exception in thread "main" java.lang.IllegalArgumentException: Not a valid class
 name: E:\Computer_Language\Java\soft_android\OpenCV-2.4.3-rc-android-sdk\OpenCV
-2.4.3-rc-android-sdk\sdk\java\bin\opencv library - 2.4.3.jar
    at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:177)
    at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:68)
    at com.sun.tools.javah.JavahTask.run(JavahTask.java:509)
    at com.sun.tools.javah.JavahTask.run(JavahTask.java:335)
    at com.sun.tools.javah.Main.main(Main.java:46)

我认为,增加的OpenCV的lib目录中的 -bootclasspath 是有用的,neccessary。这个错误是因为我只是增加了两个路径 -bootclasspath 或格式不对?

I think, adding the directory of opencv lib in -bootclasspath is useful and neccessary. The error is because i just added two path in -bootclasspath or the format is something wrong?

真的很困惑。 请给予一定的帮助,感谢ü!

Really confused. Please give some help , thank u!

推荐答案

这是我做的:

1。打开命令行,输入的(工程)/斌/类: 2,型号:javah的-classpath(opencv4android SDK路径)/ Java的/ bin中/类:(项目所在地)/斌/类-jni(包含本机库接口的Java类文件)

1.Open Command line, type to the (project)/bin/classes: 2.type: javah -classpath (opencv4android sdk path)/java/bin/classes:(your project location)/bin/classes -jni (your java class file that contains the native library interfaces)

在我的项目。我所做的:

In my project. I did:

javah的-classpath /家庭/子君/开发/ ADT / OpencvAndroid / SDK / Java的/ bin中/类:/家庭/子君/工作区/ LOCTM /斌/类-jni com.brainport.loctm.TMatching

javah -classpath /home/zijun/Dev/adt/OpencvAndroid/sdk/java/bin/classes:/home/zijun/workspace/LocTM/bin/classes -jni com.brainport.loctm.TMatching

这是在Linux Ubuntu的02年4月12号64位操作系统

That works on Linux Ubuntu 12.04.02 64bit OS

这篇关于Android的,生成JNI头文件使用javah的,显示错误不能找到org.opencv.core.Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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