不合适的链接错误 - OpenCV进行Android的非原生 [英] Unsatisfied Link Error - OpenCV for Android Non-native

查看:258
本文介绍了不合适的链接错误 - OpenCV进行Android的非原生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前几天我有关的的UnsatisfiedLinkError 运行非本地OpenCV的code。我想重新安装Eclipse和关闭/重新开放所有的包后,问题解决了,但它回来了,我把OpenCV的code到现有的的onCreate()方法后, 。

A few days ago I asked about an UnsatisfiedLinkError from running non-native OpenCV code. I thought the problem was solved after reinstalling Eclipse and closing/reopening all the packages, but it's back again after I put the OpenCV code into the existing onCreate() method.

我创建了一个新的Andr​​oid应用程序名为启动的活动。然后我去项目属性,并添加OpenCV的一个图书馆。这里的code的活性( Start.java ):

I created a new Android application with an activity called Start. I then went to project properties and added OpenCV as a library. Here's the code for the activity (Start.java):

package com.test;

import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.Menu;

public class Start extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);

        Mat Image = Highgui.imread("/image.jpg");
        if (Image == null) {
            AlertDialog ad = new AlertDialog.Builder(this).create(); 
            ad.setMessage("Fatal error: can't open /image.jpg!");  
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_start, menu);
        return true;
    }
}

和这里的日志:

08-13 12:26:14.791: E/Trace(1067): error opening trace file: No such file or directory (2)
08-13 12:26:15.191: W/dalvikvm(1067): No implementation found for native Lorg/opencv/highgui/Highgui;.imread_1:(Ljava/lang/String;)J
08-13 12:26:15.191: D/AndroidRuntime(1067): Shutting down VM
08-13 12:26:15.191: W/dalvikvm(1067): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
08-13 12:26:15.201: E/AndroidRuntime(1067): FATAL EXCEPTION: main
08-13 12:26:15.201: E/AndroidRuntime(1067): java.lang.UnsatisfiedLinkError: Native method not found: org.opencv.highgui.Highgui.imread_1:(Ljava/lang/String;)J
08-13 12:26:15.201: E/AndroidRuntime(1067):     at org.opencv.highgui.Highgui.imread_1(Native Method)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at org.opencv.highgui.Highgui.imread(Highgui.java:324)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at com.test.Start.onCreate(Start.java:18)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at android.app.Activity.performCreate(Activity.java:5008)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at android.os.Looper.loop(Looper.java:137)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at android.app.ActivityThread.main(ActivityThread.java:4745)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at java.lang.reflect.Method.invokeNative(Native Method)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at java.lang.reflect.Method.invoke(Method.java:511)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-13 12:26:15.201: E/AndroidRuntime(1067):     at dalvik.system.NativeStart.main(Native Method)

同样,这也是非本地code,因此具有不合适的链接错误并没有太大的意义。

Again, this is non-native code, so having an Unsatisfied Link Error doesn't make much sense.

推荐答案

一堆搜索后,我发现<一href="http://docs.opencv.org/trunk/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html">this:

3。如果你的应用程序项目没有一个JNI的一部分,只需复制相应的OpenCV的本地库从/ SDK /本地/库/项目目录到文件夹库/."

"3. If your application project doesn’t have a JNI part, just copy the corresponding OpenCV native libs from /sdk/native/libs/ to your project directory to folder libs/."

因此​​,这意味着复制\ armeabi,\ armeabi-V7A和\ x86的文件夹中。

So that means copy the \armeabi, \armeabi-v7a, and \x86 folders.

4。使OpenCV的应用程序中的最后一步是调用OpenCV的API之前,Java的初始code,它可以做到的,例如,在活动类的静态部分,它被执行一次,在创建类的任何实例之前:

"4. The last step of enabling OpenCV in your application is Java initialization code before call to OpenCV API. It can be done, for example, in the static section of the Activity class, which gets executed only once, before any instance of the class is created:

static {
    if (!OpenCVLoader.initDebug()) {
        // Handle initialization error
    }
}

另外,你可以把它放在onCreate方法里面:

Alternatively, you can put it inside the onCreate method:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_load_image);
    if (!OpenCVLoader.initDebug()) {
        // Handle initialization error
    }
    [...]
}

现在它的作品!

这篇关于不合适的链接错误 - OpenCV进行Android的非原生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆