我正在尝试使用一些带有JNI的c ++函数在Android应用程序上运行。
这是我在NativeLib.java中的本机函数:
private static native void drawHog(long img, long output, long decriptor, double width, double height,
double width2, double height2, int scalar, double fz_factor) ;
这是我的.h生成的.h:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_example_test_NativeLib */
#ifndef _Included_com_example_test_NativeLib
#define _Included_com_example_test_NativeLib
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_com_example_test_NativeLib_drawHog
(JNIEnv *, jclass, jlong, jlong, jlong, jdouble, jdouble, jdouble, jdouble, jint, jdouble);
#ifdef __cplusplus
}
#endif
#endif
这里是NativLib.cpp
#include<opencv2/opencv.hpp>
#include "com_example_test_NativeLib.h"
using namespace cv;
Mat get_hogdescriptor_visual_image(Mat& origImg,
vector<float>& descriptorValues,
Size winSize,
Size cellSize,
int scaleFactor,
double viz_factor);//function to draw something, defined later
JNIEXPORT void JNICALL Java_com_example_test_NativeLib_drawHog
(JNIEnv * env, jclass obj, jlong img_l, jlong outimg,jlong dec_l, jdouble _winw, jdouble _winh,
jdouble _cellw, jdouble _cellh, jint scalar, jdouble fac)
{
Mat& orgimage = *(Mat*)img_l;
Mat& out = *(Mat*)outimg;
vector<float>& descriptorValues = *(vector<float>*)dec_l;
Size winSize(_winw,_winh);
Size cellSize(_cellw, _cellh);
out = get_hogdescriptor_visual_image(orgimage,descriptorValues,winSize,cellSize,
scalar,fac);
}
Mat get_hogdescriptor_visual_image(Mat& origImg,
vector<float>& descriptorValues,
Size winSize,
Size cellSize,
int scaleFactor,
double viz_factor)
{
// do some thing.....
}
当程序运行时,它说:
07-08 14:45:40.947: D/dalvikvm(8445): Trying to load lib /data/app-lib/com.example.test-1/libNativeLib.so 0x41e4b868
07-08 14:45:40.947: D/dalvikvm(8445): Added shared lib /data/app-lib/com.example.test-1/libNativeLib.so 0x41e4b868
07-08 14:45:40.947: D/dalvikvm(8445): No JNI_OnLoad found in /data/app-lib/com.example.test-1/libNativeLib.so 0x41e4b868, skipping init
07-08 14:45:41.347: A/libc(8445): Fatal signal 11 (SIGSEGV) at 0x42ff4005 (code=2), thread 8445 (om.example.test)
我添加了一些试用来查看NativeLib.java中的问题
try {
drawHog(img.getNativeObjAddr(),outputMat.getNativeObjAddr(),descriptor.getNativeObjAddr(),winSize.width,winSize.height,
cellSize.width,cellSize.height,_scalar,_fz_factor);
} catch (Exception e) {
System.out.println(e.getStackTrace());
}
但是,此tracktrace没有打印输出....当我尝试将其作为本机应用程序进行调试时,我有以下错误报告:
https://www.dropbox.com/s/2j9pss09aa58puf/QQ%E6%88%AA%E5%9B%BE20140709155652.png
但是我检查了函数中的参数,它们都不是null。