-3

as i am implementing both OCR and Imagine SDK for our app, i need your help to solve this problem.

i have a method like below.

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());
        }

}

when i execute it. it returns "Out of memory: Heap Size=7943KB, Allocated=4113KB, Bitmap Size=24888KB, Limit=32768KB"

below is my logcat output.

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

am i doing something wrong ? Hemp help me guys

Out Sider
  • 37
  • 7

2 Answers2

0

You can try increasing the allocated memory to your application. In android Every application gets a chunk of memory allocated. but in case of image processing application it is most likely to fall short of that memory. Also try manually cleaning up the memory in your app. The android garbage collector usually have bitmap image memory leakages. you can get a good read up on this via following link bitmap memory managment

Rastee
  • 73
  • 1
  • 6
-1

Use this in your application tag of Manifest file ..

android:largeHeap="true"