2013-05-12 55 views
0

我做了一個Opencv的應用程序窗口,現在我正在使用JNI將此代碼轉換爲Android,但我遇到了一些問題。 具體而言,我的本地代碼不會做任何事情。JNI和C++的問題

這是我的Java類,我定義我的本地方法:

package com.example.telo3; 

import org.opencv.core.Mat; 

public class Process { 

    static { 
     System.loadLibrary("nativo"); 
    } 

    public Process(){ 

     dir=inicializar_nativo(); 
    } 

    public void Procesar(Mat framedetect, Mat framedraw){ 

     procesar_nativo(dir,framedetect.getNativeObjAddr(),framedraw.getNativeObjAddr()); 
    } 


    private long dir; 
    private static native long inicializar_nativo(); 
    private static native void procesar_nativo(long thiz, long framedetect, long framedraw); 

}

這是我的JNI代碼:

#include "nativo.h" 
#include <opencv2/objdetect/objdetect.hpp> 
#include <opencv2/highgui/highgui.hpp> 
#include <opencv2/imgproc/imgproc.hpp> 
#include "opencv2/video/tracking.hpp" 

#include <iostream> 
#include <stdio.h> 
#include "FaceDetector.h" 
#include "Draw.h" 
#include "Almacena.h" 
#include "Runnable.h" 



using namespace std; 
using namespace cv; 

#include <android/log.h> 

#define LOG_TAG "NATIVO" 
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) 

struct variables { 
    Almacena almacena; 
    Draw draw; 
    FaceDetector face_detector; 
}; 

JNIEXPORT jlong JNICALL Java_com_example_telo3_Process_inicializar_1nativo(
     JNIEnv *, jobject) { 

    long dir = (long) new variables(); 

    return (dir); 


} 

JNIEXPORT void JNICALL Java_com_example_telo3_Process_procesar_1nativo(JNIEnv *, 
     jobject, jlong dir, jlong framedetect, jlong framedraw) { 



Mat* telo =(Mat*)framedetect; 
Mat* telo2= (Mat*)framedraw; 

((variables*)dir)->almacena = ((variables*)dir)->face_detector.Detect(*telo); 


//almacena = face_detector.Detect(frame_gray); 


((variables*)dir)->draw.Dibujar(*telo2,((variables*)dir)->almacena); 


//frame_capturado = draw.Dibujar(frame_capturado, almacena); 



if((((variables*)dir)->almacena.get_faces()).size() ==0){ 

    LOGD("no detecto caras"); 
} 


} 

我認爲我正確使用JNI,但功能檢測不能正常工作,因爲當我使用這個,如果返回0.

回答

0

Looks li對我來說只是一個簡單的錯字。

你的包是 「com.example.telo3」
你的類是 「過程」
你的功能是 「inicializar_nativo()」

所以C++函數必須被聲明爲

JNIEXPORT jlong JNICALL Java_com_example_telo3_Process_inicializar_nativo(...) 

你已經宣佈它作爲

JNIEXPORT jlong JNICALL Java_com_example_telo3_Process_inicializar_1nativo(...) 

是否收到不滿意林k例外還是這樣?