错误视频捕获Android应用程序

时间:2013-05-17 10:48:55

标签: android opencv android-ndk video-capture

我创建了这个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();    
 }

Android.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;
}


 }

Application.mk

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

的Manifest.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)

如何解决此问题? 我正在使用Eclipse Juno,使用opencv for android ver 2.4.5。

1 个答案:

答案 0 :(得分: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