0

我创建了这个 Android 应用程序:

MainActivity.java:

package com.example.provavideocapture;

import android.os.Bundle;
import android.app.Activity;


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    videocapturing();
}   
static{
    System.loadLibrary("opencv_java");
    System.load("videocapture");
}   
public native long videocapturing();    
 }

安卓.mk

 LOCAL_PATH := $(call my-dir)

 include $(CLEAR_VARS)
 OPENCV_LIB_TYPE:=STATIC
 include C:\Users\Usr\Desktop\Android\OpenCV-2.4.5-android-sdk\sdk\native\jni\OpenCV.mk

 LOCAL_MODULE    := videocapture
 LOCAL_C_INCLUDES += $(LOCAL_PATH)
 LOCAL_LDLIBS     += -llog -ldl
 LOCAL_SRC_FILES := jniVideoCapture.cpp

 include $(BUILD_SHARED_LIBRARY)

jniVideoCapture.cpp

 #include <jni.h>
 #include <GLES/gl.h>
 #include <GLES/glext.h>
 #include <android/log.h>
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv/cv.h>
 #include <opencv2/opencv.hpp>

 using namespace cv;

 extern "C" {


JNIEXPORT jint JNICALL Java_com_example_provavideocapture_MainActivity_videocapturing(JNIEnv*, jobject)
{
    VideoCapture cap(0);
    if(!cap.isOpened())
        return -1;
    Mat edges;
    namedWindow("edges",CV_WINDOW_AUTOSIZE);
    for(;;){
        Mat frame;
        cap>>frame;
        cvtColor(frame,edges,CV_BGR2GRAY);
        GaussianBlur(edges,edges,Size(7,7),1.5,1.5);
        Canny(edges,edges,0,30,3);
        imshow("edges",edges);
        if(waitKey(30)>=30) break;
    }
    return 0;
}


 }

应用程序.mk

 APP_ABI := all
 APP_STL := gnustl_static
 APP_CPPFLAGS := -frtti -fexceptions
 APP_PLATFORM := android-9

清单.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.provavideocapture"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera.any" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.provavideocapture.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

我有这个错误(在logcat中):

05-17 12:45:34.095: E/AndroidRuntime(30365): FATAL EXCEPTION: main
05-17 12:45:34.095: E/AndroidRuntime(30365): java.lang.ExceptionInInitializerError
05-17 12:45:34.095: E/AndroidRuntime(30365):    at java.lang.Class.newInstanceImpl(Native Method)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at java.lang.Class.newInstance(Class.java:1319)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at android.app.ActivityThread.access$700(ActivityThread.java:151)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at android.os.Looper.loop(Looper.java:137)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at android.app.ActivityThread.main(ActivityThread.java:5293)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at java.lang.reflect.Method.invokeNative(Native Method)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at java.lang.reflect.Method.invoke(Method.java:511)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at dalvik.system.NativeStart.main(Native Method)
05-17 12:45:34.095: E/AndroidRuntime(30365): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opencv_java from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.provavideocapture-1.apk,libraryPath=/data/app-lib/com.example.provavideocapture-1]: findLibrary returned null
05-17 12:45:34.095: E/AndroidRuntime(30365):    at java.lang.Runtime.loadLibrary(Runtime.java:365)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at java.lang.System.loadLibrary(System.java:535)
05-17 12:45:34.095: E/AndroidRuntime(30365):    at com.example.provavideocapture.MainActivity.<clinit>(MainActivity.java:17)

我该如何解决这个问题?我正在使用适用于 android 版本 2.4.5 的 opencv 开发 Eclipse Juno。

4

1 回答 1

2

你需要这两行:

OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on

LOCAL_PATH := $(call my-dir)

和之前

include C:\Users\Usr\Desktop\Android\OpenCV-2.4.5-android-sdk\sdk\native\jni\OpenCV.mk
于 2013-08-04T06:28:45.013 回答