gpt4 book ai didi

android - "Highgui.imread"命令对 OpenCV Android 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 23:03:39 26 4
gpt4 key购买 nike

当我调用 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'

最佳答案

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

如果您首先从 openCv sdk for 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");
}

关于android - "Highgui.imread"命令对 OpenCV Android 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9151091/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com