gpt4 book ai didi

Android,用javah生成jni头文件,提示找不到org.opencv.core.Mat的错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:51:32 25 4
gpt4 key购买 nike

当我使用 javah 编译 java 类中的 native 方法以生成 JNI 头文件时,我遇到了一个令人讨厌的 jni 问题。

如果类使用了第三方包,例如:org.opencv.core.Mat,那么javah会报找不到org.opencv.core的错误。垫类。

OpenCV示例代码如下:

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);
}

首先,我使用了命令

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

然后我修改命令为

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)

我认为,在-bootclasspath中添加opencv lib的目录是有用的,也是必要的。错误是因为我刚刚在-bootclasspath 中添加了两个路径还是格式有问题?

真的很迷茫。请大家帮忙,谢谢!

最佳答案

这是我做的:

1.打开命令行,输入到(项目)/bin/classes:2.type: javah -classpath (opencv4android sdk path)/java/bin/classes:(你的项目位置)/bin/classes -jni (你的包含原生库接口(interface)的java类文件)

在我的项目中。我做了:

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

适用于 Linux Ubuntu 12.04.02 64 位操作系统

关于Android,用javah生成jni头文件,提示找不到org.opencv.core.Mat的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13438368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com