【发布时间】:2014-02-01 12:57:09
【问题描述】:
我正在做一个关于通过笔迹分析引入人性的项目。
我使用 JNI 代码执行图像预处理。 但是当程序运行时,我无法为 OpenCV 加载库,程序无法从 C++ 加载本机代码库。
错误:“无法加载 OPENCV 的信息库”
但是当我运行一个教程程序 OpenCV 库时,该库可以很好地加载。 我的程序有什么问题?
这是我的java代码:
package com.example.cobanative;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.WindowManager;
import android.widget.TextView;
public class MainActivity extends Activity {
private static final String TAG = null;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
// Load native library after(!) OpenCV initialization
System.loadLibrary("modulNative");
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
TextView textView = (TextView) findViewById(R.id.textView1);
textView.setText(stringNative());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onResume()
{
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this, mLoaderCallback);
}
public native String stringNative();
}
这是我的 C++ 代码:
#include <jni.h>
#include <android/log.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <string.h>
using namespace cv;
using namespace std;
extern "C" {
JNIEXPORT jstring JNICALL Java_com_example_cobanative_MainActivity_stringNative(JNIEnv *env, jobject obj){
jstring str = env->NewStringUTF("Hello from C++ over JNI");
return str;
}
}
我的 Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include C:/Project/OpenCV-2.4.8-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := modulNative
LOCAL_SRC_FILES := Native.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
还有我的 Application.mk :
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi
APP_PLATFORM := android-8
对不起我的英语。 感谢您的帮助。
【问题讨论】:
-
应用程序的 libs 文件夹中缺少库。
-
@EricFortin 我该如何解决?
标签: android c++ eclipse opencv java-native-interface