如何解决Imagine SDK android图像处理过程中的“内存不足”问题

时间:2015-06-08 07:41:54

标签: android abbyy

因为我正在为我们的应用程序实现OCR和Imagine SDK,所以我需要你的帮助来解决这个问题。

我有一个像下面这样的方法。

public void ImageProcessing(View v) {

        try {

                 MIContext _miContext = MIContext.getInstance();
                _miContext.clearAll();
             Uri _imageUri = Uri.fromFile(GetImageFile("form.jpg")); // GetImageFile() will return a file
            ImageOperation  _imageOperation = ImageOperation.AUTO_ENHANCE;
            OperationController _operationController = _imageOperation.getController();
                _miContext.loadSourceImage( _imageUri, this );
                final FineOperation fineOperation = _operationController.createOperation();
                _miContext.run( fineOperation );
        } catch (Exception e) {
                Log.v("mango", e.getMessage());
        }

}

当我执行它时。它返回“内存不足:堆大小= 7943KB,分配= 4113KB,位图大小= 24888KB,限制= 32768KB”

下面是我的logcat输出。

06-08 12:24:44.561: V/mango(16037): onCreate()
06-08 12:24:44.561: V/mango(16037): starting......
06-08 12:24:44.561: D/dalvikvm(16037): Trying to load lib /data/data/com.abbyy.sample/lib/libMobileImagingEngine.so 0x4051bfd8
06-08 12:24:44.881: D/dalvikvm(16037): Added shared lib /data/data/com.abbyy.sample/lib/libMobileImagingEngine.so 0x4051bfd8
06-08 12:24:44.881: V/mango(16037): MILicenser.getVersionInfo(): 1.2.1.15
06-08 12:24:44.951: V/mango(16037): MILicenser.setLicense() succeeded. Current state:

06-08 12:24:44.951: V/mango(16037):    License: Infinite.

06-08 12:24:44.951: V/mango(16037):    General availability: Enabled with results scrambling.

06-08 12:24:44.951: V/mango(16037):    Allowed platforms: All.

06-08 12:24:44.951: V/mango(16037):    Common processing available: Yes.

06-08 12:24:44.951: V/mango(16037):    Defect detecting available: Yes.

06-08 12:24:44.951: V/mango(16037):    Server side processing available: No.??
06-08 12:24:45.401: D/dalvikvm(16037): Trying to load lib /data/data/com.abbyy.sample/lib/libMobileOcrEngine.so 0x4051bfd8
06-08 12:24:45.892: D/dalvikvm(16037): Added shared lib /data/data/com.abbyy.sample/lib/libMobileOcrEngine.so 0x4051bfd8
06-08 12:24:46.032: D/dalvikvm(16037): GC_CONCURRENT freed 173K, 45% free 3109K/5639K, external 0K/0K, paused 4ms+13ms
06-08 12:24:46.392: D/ATRecorder(16037): com.htc.autotest.dlib.RecordEngine in loader dalvik.system.DexClassLoader@40582d68
06-08 12:24:46.402: D/WindowManagerImpl(16037): addView, new view, mViews[0]: com.android.internal.policy.impl.PhoneWindow$DecorView@4055b6e8
06-08 12:26:46.029: D/View(16037): onTouchEvent: viewFlags: 0x18004001
06-08 12:26:46.029: D/View(16037): onTouchEvent: isFocusable: true, isFocusableInTouchMode: false, isFocused: false; focusTaken: false
06-08 12:26:57.210: D/dalvikvm(16037): GC_EXTERNAL_ALLOC freed 184K, 44% free 3248K/5767K, external 0K/0K, paused 31ms
06-08 12:26:58.071: D/ATRecorder(16037): com.htc.autotest.dlib.RecordEngine in loader dalvik.system.DexClassLoader@4059fd80
06-08 12:26:58.071: D/WindowManagerImpl(16037): addView, new view, mViews[1]: com.android.internal.policy.impl.PhoneWindow$DecorView@4059cad0
06-08 12:26:58.311: D/WindowManagerImpl(16037): finishRemoveViewLocked, mViews[0]: com.android.internal.policy.impl.PhoneWindow$DecorView@4055b6e8
06-08 12:26:59.632: D/View(16037): onTouchEvent: viewFlags: 0x18004001
06-08 12:26:59.632: D/View(16037): onTouchEvent: isFocusable: true, isFocusableInTouchMode: false, isFocused: false; focusTaken: false
06-08 12:26:59.672: D/dalvikvm(16037): GC_EXPLICIT freed 103K, 45% free 3189K/5767K, external 24888K/26936K, paused 27ms
06-08 12:26:59.763: I/dalvikvm-heap(16037): Clamp target GC heap from 32.598MB to 32.000MB
06-08 12:26:59.763: D/dalvikvm(16037): GC_FOR_MALLOC freed 552K, 44% free 4145K/7367K, external 24888K/26936K, paused 17ms
06-08 12:26:59.763: I/dalvikvm-heap(16037): Forcing collection of SoftReferences for 1966096-byte allocation
06-08 12:26:59.773: I/dalvikvm-heap(16037): Clamp target GC heap from 32.566MB to 32.000MB
06-08 12:26:59.773: D/dalvikvm(16037): GC_FOR_MALLOC freed 32K, 45% free 4113K/7367K, external 24888K/26936K, paused 18ms
06-08 12:26:59.783: E/dalvikvm-heap(16037): Out of memory on a 1966096-byte allocation.
06-08 12:26:59.783: I/dalvikvm(16037): "main" prio=5 tid=1 RUNNABLE
06-08 12:26:59.783: I/dalvikvm(16037):   | group="main" sCount=0 dsCount=0 obj=0x400275d8 self=0xd050
06-08 12:26:59.783: I/dalvikvm(16037):   | sysTid=16037 nice=0 sched=0/0 cgrp=default handle=-1345002112
06-08 12:26:59.783: I/dalvikvm(16037):   | schedstat=( 1244079605 798675516 1219 )
06-08 12:26:59.783: I/dalvikvm(16037):   at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:~91)
06-08 12:26:59.783: I/dalvikvm(16037):   at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:216)
06-08 12:26:59.783: I/dalvikvm(16037):   at com.abbyy.mobile.imaging.MIExporter.importJPEG(MIExporter.java:102)
06-08 12:26:59.783: I/dalvikvm(16037):   at com.abbyy.sample.MIContext.loadSourceImage(MIContext.java:114)
06-08 12:26:59.783: I/dalvikvm(16037):   at com.abbyy.sample.ScanTheForm.ImageProcessing(ScanTheForm.java:71)
06-08 12:26:59.783: I/dalvikvm(16037):   at java.lang.reflect.Method.invokeNative(Native Method)
06-08 12:26:59.783: I/dalvikvm(16037):   at java.lang.reflect.Method.invoke(Method.java:507)
06-08 12:26:59.783: I/dalvikvm(16037):   at android.view.View$1.onClick(View.java:2187)
06-08 12:26:59.793: I/dalvikvm(16037):   at android.view.View.performClick(View.java:2533)
06-08 12:26:59.793: I/dalvikvm(16037):   at android.view.View$PerformClick.run(View.java:9320)
06-08 12:26:59.793: I/dalvikvm(16037):   at android.os.Handler.handleCallback(Handler.java:587)
06-08 12:26:59.793: I/dalvikvm(16037):   at android.os.Handler.dispatchMessage(Handler.java:92)
06-08 12:26:59.793: I/dalvikvm(16037):   at android.os.Looper.loop(Looper.java:150)
06-08 12:26:59.793: I/dalvikvm(16037):   at android.app.ActivityThread.main(ActivityThread.java:4385)
06-08 12:26:59.793: I/dalvikvm(16037):   at java.lang.reflect.Method.invokeNative(Native Method)
06-08 12:26:59.793: I/dalvikvm(16037):   at java.lang.reflect.Method.invoke(Method.java:507)
06-08 12:26:59.793: I/dalvikvm(16037):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
06-08 12:26:59.793: I/dalvikvm(16037):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
06-08 12:26:59.793: I/dalvikvm(16037):   at dalvik.system.NativeStart.main(Native Method)
06-08 12:26:59.793: E/dalvikvm(16037): Out of memory: Heap Size=7943KB, Allocated=4113KB, Bitmap Size=24888KB, Limit=32768KB
06-08 12:26:59.793: E/dalvikvm(16037): Extra info: Footprint=7367KB, Allowed Footprint=7943KB, Trimmed=480KB
06-08 12:26:59.793: D/AndroidRuntime(16037): Shutting down VM
06-08 12:26:59.793: W/dalvikvm(16037): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
06-08 12:26:59.803: E/AndroidRuntime(16037): FATAL EXCEPTION: main
06-08 12:26:59.803: E/AndroidRuntime(16037): java.lang.IllegalStateException: Could not execute method of the activity
06-08 12:26:59.803: E/AndroidRuntime(16037):    at android.view.View$1.onClick(View.java:2192)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at android.view.View.performClick(View.java:2533)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at android.view.View$PerformClick.run(View.java:9320)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at android.os.Handler.handleCallback(Handler.java:587)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at android.os.Looper.loop(Looper.java:150)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at android.app.ActivityThread.main(ActivityThread.java:4385)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at java.lang.reflect.Method.invokeNative(Native Method)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at java.lang.reflect.Method.invoke(Method.java:507)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at dalvik.system.NativeStart.main(Native Method)
06-08 12:26:59.803: E/AndroidRuntime(16037): Caused by: java.lang.reflect.InvocationTargetException
06-08 12:26:59.803: E/AndroidRuntime(16037):    at java.lang.reflect.Method.invokeNative(Native Method)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at java.lang.reflect.Method.invoke(Method.java:507)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at android.view.View$1.onClick(View.java:2187)
06-08 12:26:59.803: E/AndroidRuntime(16037):    ... 11 more
06-08 12:26:59.803: E/AndroidRuntime(16037): Caused by: java.lang.OutOfMemoryError: (Heap Size=7943KB, Allocated=4113KB, Bitmap Size=24888KB)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:216)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at com.abbyy.mobile.imaging.MIExporter.importJPEG(MIExporter.java:102)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at com.abbyy.sample.MIContext.loadSourceImage(MIContext.java:114)
06-08 12:26:59.803: E/AndroidRuntime(16037):    at com.abbyy.sample.ScanTheForm.ImageProcessing(ScanTheForm.java:71)
06-08 12:26:59.803: E/AndroidRuntime(16037):    ... 14 more
我做错了什么?麻帮帮我们

2 个答案:

答案 0 :(得分:0)

您可以尝试增加应用程序的已分配内存。在android中,每个应用程序都会分配一大块内存。但在图像处理应用的情况下,它很可能没有那个记忆。 还可以尝试手动清理应用中的内存。 android垃圾收集器通常有位图图像内存泄漏。 你可以通过以下链接得到一个很好的阅读 bitmap memory managment

答案 1 :(得分:-1)

在Manifest文件的应用程序标记中使用它。

android:largeHeap="true"