失礼いたします。
現在、趣味でOpenCVのAndroid版を使ったアプリを作っております。
しかし、アプリを実行すると、LogCatに題目のエラーが発生した後、強制終了してしまいます。
ソースは以下の通りです。
以下の通り、画像処理の部分についてはAndroidNDKの機能を使用しております。
MainActivity.java
package com.example.foo;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;
public class MainActivity extends Activity implements CvCameraViewListener2 {
private static final String TAG = "MainActivity";
private Mat mMatCamera;
private Mat mMatView;
private CameraBridgeViewBase mOpenCvCameraView;
static {
if (!OpenCVLoader.initDebug()) {
// Handle initialization error
} else {
System.loadLibrary("foo");
}
}
public MainActivity() {
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.foo);
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.foo_activity_surface_view);
mOpenCvCameraView.setCvCameraViewListener(this);
}
@Override
public void onPause()
{
super.onPause();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
@Override
public void onResume()
{
super.onResume();
mOpenCvCameraView.enableView();
}
@Override
public void onDestroy() {
super.onDestroy();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
public void onCameraViewStarted(int width, int height) {
mMatView = new Mat(height, width, CvType.CV_8UC4);
}
public void onCameraViewStopped() {
if (mMatCamera != null)
mMatCamera.release();
if (mMatView != null)
mMatView.release();
}
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mMatCamera = inputFrame.rgba();
foo(mMatCamera.getNativeObjAddr(), mMatView.getNativeObjAddr());
return mMatView;
}
private native void foo(long matCameraAddr, long matViewAddr);
}
jni_part.cpp
#include <jni.h>
#include <opencv2/core/core.hpp>
JNIEXPORT void JNICALL Java_com_example_foo_MainActivity_foo(JNIEnv*, jobject, jlong matCameraAddr, jlong matViewAddr)
{
// 何か処理
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
include ../../sdk/native/jni/OpenCV.mk
LOCAL_MODULE := foo
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
エラーの内容は以下の通りです。
03-08 10:58:42.984: E/AndroidRuntime(26065): FATAL EXCEPTION: Thread-157860
03-08 10:58:42.984: E/AndroidRuntime(26065): Process: com.example.foo, PID: 26065
03-08 10:58:42.984: E/AndroidRuntime(26065): java.lang.UnsatisfiedLinkError: Native method not found: com.example.foo.MainActivity.foo:(JJ)V
03-08 10:58:42.984: E/AndroidRuntime(26065): at com.example.foo.MainActivity.foo(Native Method)
03-08 10:58:42.984: E/AndroidRuntime(26065): at com.example.foo.MainActivity.onCameraFrame(MainActivity.java:81)
03-08 10:58:42.984: E/AndroidRuntime(26065): at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:387)
03-08 10:58:42.984: E/AndroidRuntime(26065): at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:328)
03-08 10:58:42.984: E/AndroidRuntime(26065): at java.lang.Thread.run(Thread.java:841)
以上、よろしくお願いいたします。