Opencv找不到找不到本机/本机方法的实现

时间:2014-01-09 17:49:24

标签: android c++ opencv android-ndk

LogCat / com.example.jni

01-10 01:58:55.102: D/JavaCameraView(22833): Starting processing thread
01-10 01:58:55.112: E/BufferQueue(22833): [unnamed-22833-1] dequeueBuffer: mMinUndequeuedBuffers=2 exceeded (dequeued=6)
01-10 01:58:55.142: D/JavaCameraView(22833): Preview Frame received. Frame size: 373248
01-10 01:58:55.142: E/BufferQueue(22833): [unnamed-22833-1] dequeueBuffer: mMinUndequeuedBuffers=2 exceeded (dequeued=5)
01-10 01:58:55.162: W/dalvikvm(22833): No implementation found for native Lcom/example/jni/TutorialActivity;.MainActivity:(JJI)V
01-10 01:58:55.162: W/dalvikvm(22833): threadid=11: thread exiting with uncaught exception (group=0x40bd3438)
01-10 01:58:55.172: E/AndroidRuntime(22833): FATAL EXCEPTION: Thread-2008
01-10 01:58:55.172: E/AndroidRuntime(22833): java.lang.UnsatisfiedLinkError: Native method not found: com.example.jni.TutorialActivity.MainActivity:(JJI)V
01-10 01:58:55.172: E/AndroidRuntime(22833):    at com.example.jni.TutorialActivity.MainActivity(Native Method)
01-10 01:58:55.172: E/AndroidRuntime(22833):    at com.example.jni.TutorialActivity.onCameraFrame(TutorialActivity.java:133)
01-10 01:58:55.172: E/AndroidRuntime(22833):    at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:387)
01-10 01:58:55.172: E/AndroidRuntime(22833):    at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:328)
01-10 01:58:55.172: E/AndroidRuntime(22833):    at java.lang.Thread.run(Thread.java:856)
01-10 01:58:55.182: D/JavaCameraView(22833): Preview Frame received. Frame size: 373248
01-10 01:58:55.192: D/JavaCameraView(22833): Disconnecting from camera

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
OPENCV_LIB_TYPE:=STATIC

include ../../sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := ndklib
LOCAL_SRC_FILES := TutorialActivity.cpp
LOCAL_SRC_FILES := set.cpp
LOCAL_SRC_FILES := hand_calc.cpp
LOCAL_SRC_FILES := hand_core.cpp
LOCAL_SRC_FILES := hand_define.h
LOCAL_LDLIBS +=  -llog -ldl

include $(BUILD_SHARED_LIBRARY)

JNI / TutorialActivity.cpp

#include <jni.h>
#include <hand_define.h>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <vector>
#include <hand_calc.cpp>
#include <hand_core.cpp>
#include <set.cpp>

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

using namespace std;
using namespace cv;
    extern "c"{

    JNIEXPORT void JNICALL Java_com_example_jni_TutorialActivity_MainActivity
      (JNIEnv *, jobject, jlong addrRgb, jlong addrsss, jint btnclick);

    JNIEXPORT void JNICALL Java_com_example_jni_TutorialActivity_MainActivity
      (JNIEnv *, jobject, jlong addrRgb, jlong addrsss, jint btnclick)
    {
    .
    .
    .
    }

    }

TutorialActivity.java

       package com.example.jni;

        import java.io.FileOutputStream;

        public class TutorialActivity extends Activity implements CvCameraViewListener2  {
        .
        .
        .
        private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
                @Override
                public void onManagerConnected(int status) {
                    switch (status) {
                        case LoaderCallbackInterface.SUCCESS:
                        {
                            Log.i(TAG, "OpenCV loaded successfully");
                            System.loadLibrary("ndklib");

                            mOpenCvCameraView.enableView();
                        } break;
                        default:
                        {
                            super.onManagerConnected(status);
                        } break;
                    }
                }
            };
        .
        .
        .
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    final int viewMode = mViewMode;       

        mRgba = inputFrame.rgba();
        MainActivity(mRgba.getNativeObjAddr(), sss.getNativeObjAddr(), btnclick);
        Button btn = (Button)findViewById(R.id.button2);

        btn.setOnClickListener(new Button.OnClickListener(){
                @Override
                    public void onClick(View v) {
                        btnclick = 1;
                        MainActivity(mRgba.getNativeObjAddr(), sss.getNativeObjAddr(), btnclick);
                        //Core.normalize(sss, sss, 0, 255, Core.NORM_MINMAX, CvType.CV_8U);
                        Utils.matToBitmap(sss, mbit);
                        mimg.setImageBitmap(mbit);
                        btnclick = 0;
                    }           
                });
            return mRgba;
        }

            public native void MainActivity(long Rgba, long Hand, int Clk);
}

首先,对我糟糕的编码技巧感到抱歉。

我正在尝试使用jni在java上使用c ++代码。当我从Opencv for Android示例Tutorial-2复制和编辑代码体时,我的c ++代码运行良好。但是,当我尝试使用像教程2这样的新Android应用程序项目时,它不起作用并显示“Opencv没有找到本机/本机方法的实现”,即使有任何错误。

项目的特性 * C / C ++编译 build命令:$ {NDKROOT} /ndk-build.cmd 行为 - 自动构建:已选中

* c / c ++ general - 路径和符号 - JNUc ++ 添加了一些目录。

0 个答案:

没有答案