Android:如何将图像从图库加载到 OpenCv Mat 变量中?

发布于 2025-01-03 09:45:11 字数 3921 浏览 1 评论 0原文

我目前正在尝试对存储在图像库文件夹中的图像运行一些opencv 过滤器(即查找egde、Median 等)。

但我在加载图像时遇到错误。我的设备是 Galaxy Tab 10.1,带有 android 3.2,我的 opencv - API 级别 8。

我在按钮上有以下源:

  @Override
    public void onClick(View v) {

      Bitmap myBitmap = BitmapFactory.decodeFile("/sdcard/image1.jpg");                 
      Bitmap myBitmap32 = myBitmap.copy(Bitmap.Config.ARGB_8888, true);
      Mat pic1 = Utils.bitmapToMat(myBitmap32);

    }

这是 LogCat:

02-07 12:31:27.290: I/System.out(16522): Not a DRM File, opening notmally
02-07 12:31:27.290: I/System.out(16522): buffer returned 
02-07 12:31:27.310: D/dalvikvm(16522): GC_FOR_ALLOC freed 11K, 21% free 6975K/8775K, paused 19ms
02-07 12:31:27.320: I/dalvikvm-heap(16522): Grow heap (frag case) to 12.918MB for 6291472-byte allocation
02-07 12:31:27.340: D/dalvikvm(16522): GC_FOR_ALLOC freed <1K, 13% free 13119K/14983K, paused 19ms
02-07 12:31:27.380: D/dalvikvm(16522): GC_CONCURRENT freed 0K, 13% free 13119K/14983K, paused 2ms+2ms
02-07 12:31:27.710: D/dalvikvm(16522): GC_FOR_ALLOC freed 55K, 13% free 13063K/14983K, paused 20ms
02-07 12:31:27.730: I/dalvikvm-heap(16522): Grow heap (frag case) to 24.864MB for 12582928-byte allocation
02-07 12:31:27.780: D/dalvikvm(16522): GC_FOR_ALLOC freed 0K, 8% free 25351K/27335K, paused 21ms
02-07 12:31:27.830: D/dalvikvm(16522): GC_CONCURRENT freed <1K, 8% free 25351K/27335K, paused 2ms+3ms
02-07 12:31:27.890: W/dalvikvm(16522): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/android/Utils;
02-07 12:31:27.890: D/AndroidRuntime(16522): Shutting down VM
02-07 12:31:27.890: W/dalvikvm(16522): threadid=1: thread exiting with uncaught exception (group=0x400fc760)
02-07 12:31:27.890: E/AndroidRuntime(16522): FATAL EXCEPTION: main
02-07 12:31:27.890: E/AndroidRuntime(16522): java.lang.ExceptionInInitializerError
02-07 12:31:27.890: E/AndroidRuntime(16522):    at photo.klu.PhotoKLUActivity$1.onClick(PhotoKLUActivity.java:82)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at android.view.View.performClick(View.java:3127)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at android.view.View$PerformClick.run(View.java:12025)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at android.os.Handler.handleCallback(Handler.java:587)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at android.os.Looper.loop(Looper.java:132)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at android.app.ActivityThread.main(ActivityThread.java:4126)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at java.lang.reflect.Method.invokeNative(Native Method)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at java.lang.reflect.Method.invoke(Method.java:491)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at dalvik.system.NativeStart.main(Native Method)
02-07 12:31:27.890: E/AndroidRuntime(16522): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opencv_java: findLibrary returned null
02-07 12:31:27.890: E/AndroidRuntime(16522):    at java.lang.Runtime.loadLibrary(Runtime.java:425)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at java.lang.System.loadLibrary(System.java:554)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at org.opencv.android.Utils.<clinit>(Utils.java:86)
02-07 12:31:27.890: E/AndroidRuntime(16522):    ... 12 more
02-07 12:31:30.010: I/dalvikvm(16522): threadid=4: reacting to signal 3
02-07 12:31:30.010: I/dalvikvm(16522): Wrote stack traces to '/data/anr/traces.txt'
02-07 12:31:37.470: I/Process(16522): Sending signal. PID: 16522 SIG: 9

有什么想法吗?

谢谢。

I'm currently try to run some opencv filters (i.e find egde, Median, ...) on images which are stored in the image gallery folder.

But I get error for loading image. My device is galaxy tab 10.1 with android 3.2, my opencv - API level 8.

I have the following source on a Button:

  @Override
    public void onClick(View v) {

      Bitmap myBitmap = BitmapFactory.decodeFile("/sdcard/image1.jpg");                 
      Bitmap myBitmap32 = myBitmap.copy(Bitmap.Config.ARGB_8888, true);
      Mat pic1 = Utils.bitmapToMat(myBitmap32);

    }

Here is LogCat:

02-07 12:31:27.290: I/System.out(16522): Not a DRM File, opening notmally
02-07 12:31:27.290: I/System.out(16522): buffer returned 
02-07 12:31:27.310: D/dalvikvm(16522): GC_FOR_ALLOC freed 11K, 21% free 6975K/8775K, paused 19ms
02-07 12:31:27.320: I/dalvikvm-heap(16522): Grow heap (frag case) to 12.918MB for 6291472-byte allocation
02-07 12:31:27.340: D/dalvikvm(16522): GC_FOR_ALLOC freed <1K, 13% free 13119K/14983K, paused 19ms
02-07 12:31:27.380: D/dalvikvm(16522): GC_CONCURRENT freed 0K, 13% free 13119K/14983K, paused 2ms+2ms
02-07 12:31:27.710: D/dalvikvm(16522): GC_FOR_ALLOC freed 55K, 13% free 13063K/14983K, paused 20ms
02-07 12:31:27.730: I/dalvikvm-heap(16522): Grow heap (frag case) to 24.864MB for 12582928-byte allocation
02-07 12:31:27.780: D/dalvikvm(16522): GC_FOR_ALLOC freed 0K, 8% free 25351K/27335K, paused 21ms
02-07 12:31:27.830: D/dalvikvm(16522): GC_CONCURRENT freed <1K, 8% free 25351K/27335K, paused 2ms+3ms
02-07 12:31:27.890: W/dalvikvm(16522): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/android/Utils;
02-07 12:31:27.890: D/AndroidRuntime(16522): Shutting down VM
02-07 12:31:27.890: W/dalvikvm(16522): threadid=1: thread exiting with uncaught exception (group=0x400fc760)
02-07 12:31:27.890: E/AndroidRuntime(16522): FATAL EXCEPTION: main
02-07 12:31:27.890: E/AndroidRuntime(16522): java.lang.ExceptionInInitializerError
02-07 12:31:27.890: E/AndroidRuntime(16522):    at photo.klu.PhotoKLUActivity$1.onClick(PhotoKLUActivity.java:82)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at android.view.View.performClick(View.java:3127)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at android.view.View$PerformClick.run(View.java:12025)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at android.os.Handler.handleCallback(Handler.java:587)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at android.os.Looper.loop(Looper.java:132)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at android.app.ActivityThread.main(ActivityThread.java:4126)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at java.lang.reflect.Method.invokeNative(Native Method)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at java.lang.reflect.Method.invoke(Method.java:491)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at dalvik.system.NativeStart.main(Native Method)
02-07 12:31:27.890: E/AndroidRuntime(16522): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opencv_java: findLibrary returned null
02-07 12:31:27.890: E/AndroidRuntime(16522):    at java.lang.Runtime.loadLibrary(Runtime.java:425)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at java.lang.System.loadLibrary(System.java:554)
02-07 12:31:27.890: E/AndroidRuntime(16522):    at org.opencv.android.Utils.<clinit>(Utils.java:86)
02-07 12:31:27.890: E/AndroidRuntime(16522):    ... 12 more
02-07 12:31:30.010: I/dalvikvm(16522): threadid=4: reacting to signal 3
02-07 12:31:30.010: I/dalvikvm(16522): Wrote stack traces to '/data/anr/traces.txt'
02-07 12:31:37.470: I/Process(16522): Sending signal. PID: 16522 SIG: 9

Any ideas?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅沫记忆 2025-01-10 09:45:11

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

The openCV library is not attached to your application. Please do the following (i assume that the openCV library is imported to your workspace). On Package Explorer > Right click on the application project > properties > under Library click Add > select openCV Be sure that on Java Build Path you don't have anything related to openCV

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文