“Highgui.imread”命令不适用于OpenCV Android

时间:2012-02-05 16:58:06

标签: android opencv

当我拨打 Highgui.imread 命令时,我的手机上出现意外异常

我想将SDCard中的图像加载到MAT变量。

File imgFile = new  File("/sdcard/image1.jpg");
if(imgFile.exists())
{ 
 Mat pic1 = Highgui.imread(imgFile.getAbsolutePath()); 
}

我正在使用 Galaxy Tab 10.1 + Android操作系统:3.2 内核版本:2.6.36.3

设备错误:应用程序project1(进程prj.project)意外停止。请再试一次。

提前感谢您的帮助。

此致 阿里

logcat的:

02-06 11:08:23.620: W/dalvikvm(5853): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/highgui/Highgui;    
02-06 11:08:23.620: D/AndroidRuntime(5853): Shutting down VM    
02-06 11:08:23.620: W/dalvikvm(5853): threadid=1: thread exiting with uncaught exception (group=0x400fc760)    
02-06 11:08:23.620: E/AndroidRuntime(5853): FATAL EXCEPTION: main    
02-06 11:08:23.620: E/AndroidRuntime(5853): java.lang.ExceptionInInitializerError    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at photo.klu.PhotoKLUActivity$1.onClick(PhotoKLUActivity.java:89)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at android.view.View.performClick(View.java:3127)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at android.view.View$PerformClick.run(View.java:12025)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at android.os.Handler.handleCallback(Handler.java:587)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at android.os.Handler.dispatchMessage(Handler.java:92)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at android.os.Looper.loop(Looper.java:132)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at android.app.ActivityThread.main(ActivityThread.java:4126)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at java.lang.reflect.Method.invokeNative(Native Method)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at java.lang.reflect.Method.invoke(Method.java:491)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at dalvik.system.NativeStart.main(Native Method)    
02-06 11:08:23.620: E/AndroidRuntime(5853): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opencv_java: findLibrary returned null    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at java.lang.Runtime.loadLibrary(Runtime.java:425)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at java.lang.System.loadLibrary(System.java:554)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     at org.opencv.highgui.Highgui.<clinit>(Highgui.java:313)    
02-06 11:08:23.620: E/AndroidRuntime(5853):     ... 12 more    
02-06 11:08:25.640: I/dalvikvm(5853): threadid=4: reacting to signal 3    
02-06 11:08:25.640: I/dalvikvm(5853): Wrote stack traces to '/data/anr/traces.txt'

2 个答案:

答案 0 :(得分:1)

如果你无法配置opencv,请查看本教程 http://opencv.org/platforms/android.html

如果你首先从openCv sdk调用android的方法,你就要实现;

private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
   switch (status) {
       case LoaderCallbackInterface.SUCCESS:
       {
      Log.i(TAG, "OpenCV loaded successfully");
      // Create and set View
      setContentView(R.layout.main);
       } break;
       default:
       {
      super.onManagerConnected(status);
       } break;
   }
    }
};

然后在您的方法中调用以下内容。

 if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack))
    {
      Log.e(TAG, "Cannot connect to OpenCV Manager");
    }

答案 1 :(得分:0)

openCV库未附加到您的应用程序。 请执行以下操作(我假设openCV库已导入您的工作区)。 在包资源管理器上&gt;右键单击应用程序项目&gt;属性&gt;在图书馆下点击添加&gt;选择openCV 确保在Java Build Path上没有与openCV相关的任何内容