Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8307209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:28:50+00:00 2026-06-08T18:28:50+00:00

I want to use Cube option but getting error. my code is as following.

  • 0

I want to use Cube option but getting error.
my code is as following.

   package com.datumdroid.android.ocr.simple;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;

import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.googlecode.tesseract.android.TessBaseAPI;

public class SimpleAndroidOCRActivity extends Activity {
    public static final String PACKAGE_NAME = "com.datumdroid.android.ocr.simple";
    public static final String DATA_PATH = Environment
            .getExternalStorageDirectory().toString() + "/SimpleAndroidOCR/";

    // You should have the trained data file in assets folder
    // You can get them at:
    // http://code.google.com/p/tesseract-ocr/downloads/list
    public static final String lang = "eng";

    private static final String TAG = "SimpleAndroidOCR.java";

    protected Button _button;
    // protected ImageView _image;
    protected EditText _field;
    protected String _path;
    protected boolean _taken;

    protected static final String PHOTO_TAKEN = "photo_taken";

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        String[] paths = new String[] { DATA_PATH, DATA_PATH + "tessdata/" };

        for (String path : paths) {
            File dir = new File(path);
            if (!dir.exists()) {
                if (!dir.mkdirs()) {
                    Log.v(TAG, "ERROR: Creation of directory " + path + " on sdcard failed");
                    return;
                } else {
                    Log.v(TAG, "Created directory " + path + " on sdcard");
                }
            }

        }

        // lang.traineddata file with the app (in assets folder)
                // You can get them at:
                // http://code.google.com/p/tesseract-ocr/downloads/list
                // This area needs work and optimization
                if (!(new File(DATA_PATH + "tessdata/" + lang + ".traineddata")).exists()) {
                    try {

                        AssetManager assetManager = getAssets();
                        InputStream in = assetManager.open("tessdata/eng.traineddata");
                        //GZIPInputStream gin = new GZIPInputStream(in);
                        OutputStream out = new FileOutputStream(DATA_PATH
                                + "tessdata/eng.traineddata");

                        // Transfer bytes from in to out
                        byte[] buf = new byte[1024];
                        int len;
                        //while ((lenf = gin.read(buff)) > 0) {
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        in.close();
                        //gin.close();
                        out.close();

                        Log.v(TAG, "Copied " + lang + " traineddata");
                    } catch (IOException e) {
                        Log.e(TAG, "Was unable to copy " + lang + " traineddata " + e.toString());
                    }
                }


                if (!(new File(DATA_PATH + "tessdata/ara.cube.bigrams")).exists()) {
                    try {

                        AssetManager assetManager = getAssets();
                        InputStream in = assetManager.open("tessdata/ara.cube.bigrams");
                        //GZIPInputStream gin = new GZIPInputStream(in);
                        OutputStream out = new FileOutputStream(DATA_PATH
                                + "tessdata/ara.cube.bigrams");

                        // Transfer bytes from in to out
                        byte[] buf = new byte[1024];
                        int len;
                        //while ((lenf = gin.read(buff)) > 0) {
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        in.close();
                        //gin.close();
                        out.close();

                        Log.v(TAG, "Copied ara.cube.bigrams");
                    } catch (IOException e) {
                        Log.e(TAG, "Was unable to copy ara.cube.bigrams " + e.toString());
                    }
                }


                if (!(new File(DATA_PATH + "tessdata/ara.cube.fold")).exists()) {
                    try {

                        AssetManager assetManager = getAssets();
                        InputStream in = assetManager.open("tessdata/ara.cube.fold");
                        //GZIPInputStream gin = new GZIPInputStream(in);
                        OutputStream out = new FileOutputStream(DATA_PATH
                                + "tessdata/ara.cube.fold");

                        // Transfer bytes from in to out
                        byte[] buf = new byte[1024];
                        int len;
                        //while ((lenf = gin.read(buff)) > 0) {
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        in.close();
                        //gin.close();
                        out.close();

                        Log.v(TAG, "Copied ara.cube.fold");
                    } catch (IOException e) {
                        Log.e(TAG, "Was unable to copy ara.cube.fold " + e.toString());
                    }
                }


                if (!(new File(DATA_PATH + "tessdata/ara.cube.lm")).exists()) {
                    try {

                        AssetManager assetManager = getAssets();
                        InputStream in = assetManager.open("tessdata/ara.cube.lm");
                        //GZIPInputStream gin = new GZIPInputStream(in);
                        OutputStream out = new FileOutputStream(DATA_PATH
                                + "tessdata/ara.cube.lm");

                        // Transfer bytes from in to out
                        byte[] buf = new byte[1024];
                        int len;
                        //while ((lenf = gin.read(buff)) > 0) {
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        in.close();
                        //gin.close();
                        out.close();

                        Log.v(TAG, "Copied ara.cube.lm");
                    } catch (IOException e) {
                        Log.e(TAG, "Was unable to copy ara.cube.lm " + e.toString());
                    }
                }

                if (!(new File(DATA_PATH + "tessdata/ara.cube.nn")).exists()) {
                    try {

                        AssetManager assetManager = getAssets();
                        InputStream in = assetManager.open("tessdata/ara.cube.nn");
                        //GZIPInputStream gin = new GZIPInputStream(in);
                        OutputStream out = new FileOutputStream(DATA_PATH
                                + "tessdata/ara.cube.nn");

                        // Transfer bytes from in to out
                        byte[] buf = new byte[1024];
                        int len;
                        //while ((lenf = gin.read(buff)) > 0) {
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        in.close();
                        //gin.close();
                        out.close();

                        Log.v(TAG, "Copied ara.cube.nn");
                    } catch (IOException e) {
                        Log.e(TAG, "Was unable to copy ara.cube.nn " + e.toString());
                    }
                }

                if (!(new File(DATA_PATH + "tessdata/ara.cube.params")).exists()) {
                    try {

                        AssetManager assetManager = getAssets();
                        InputStream in = assetManager.open("tessdata/ara.cube.params");
                        //GZIPInputStream gin = new GZIPInputStream(in);
                        OutputStream out = new FileOutputStream(DATA_PATH
                                + "tessdata/ara.cube.params");

                        // Transfer bytes from in to out
                        byte[] buf = new byte[1024];
                        int len;
                        //while ((lenf = gin.read(buff)) > 0) {
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        in.close();
                        //gin.close();
                        out.close();

                        Log.v(TAG, "Copied ara.cube.params");
                    } catch (IOException e) {
                        Log.e(TAG, "Was unable to copy ara.cube.params " + e.toString());
                    }
                }

                if (!(new File(DATA_PATH + "tessdata/ara.cube.size")).exists()) {
                    try {

                        AssetManager assetManager = getAssets();
                        InputStream in = assetManager.open("tessdata/ara.cube.size");
                        //GZIPInputStream gin = new GZIPInputStream(in);
                        OutputStream out = new FileOutputStream(DATA_PATH
                                + "tessdata/ara.cube.size");

                        // Transfer bytes from in to out
                        byte[] buf = new byte[1024];
                        int len;
                        //while ((lenf = gin.read(buff)) > 0) {
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        in.close();
                        //gin.close();
                        out.close();

                        Log.v(TAG, "Copied ara.cube.size");
                    } catch (IOException e) {
                        Log.e(TAG, "Was unable to copy ara.cube.size " + e.toString());
                    }
                }


                if (!(new File(DATA_PATH + "tessdata/ara.cube.word-freq")).exists()) {
                    try {

                        AssetManager assetManager = getAssets();
                        InputStream in = assetManager.open("tessdata/ara.cube.word-freq");
                        //GZIPInputStream gin = new GZIPInputStream(in);
                        OutputStream out = new FileOutputStream(DATA_PATH
                                + "tessdata/ara.cube.word-freq");

                        // Transfer bytes from in to out
                        byte[] buf = new byte[1024];
                        int len;
                        //while ((lenf = gin.read(buff)) > 0) {
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        in.close();
                        //gin.close();
                        out.close();

                        Log.v(TAG, "Copied ara.cube.word-freq");
                    } catch (IOException e) {
                        Log.e(TAG, "Was unable to copy ara.cube.word-freq " + e.toString());
                    }
                }

                if (!(new File(DATA_PATH + "tessdata/ara.traineddata")).exists()) {
                    try {

                        AssetManager assetManager = getAssets();
                        InputStream in = assetManager.open("tessdata/ara.traineddata");
                        //GZIPInputStream gin = new GZIPInputStream(in);
                        OutputStream out = new FileOutputStream(DATA_PATH
                                + "tessdata/ara.traineddata");

                        // Transfer bytes from in to out
                        byte[] buf = new byte[1024];
                        int len;
                        //while ((lenf = gin.read(buff)) > 0) {
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        in.close();
                        //gin.close();
                        out.close();

                        Log.v(TAG, "Copied ara.traineddata");
                    } catch (IOException e) {
                        Log.e(TAG, "Was unable to copy ara.traineddata " + e.toString());
                    }
                }


        // _image = (ImageView) findViewById(R.id.image);
        _field = (EditText) findViewById(R.id.field);
        _button = (Button) findViewById(R.id.button);
        _button.setOnClickListener(new ButtonClickHandler());

        _path = DATA_PATH + "/ocr.jpg";
    }

    public class ButtonClickHandler implements View.OnClickListener {
        public void onClick(View view) {
            Log.v(TAG, "Starting Camera app");
            startCameraActivity();
        }
    }

    // Simple android photo capture:
    // http://labs.makemachine.net/2010/03/simple-android-photo-capture/

    protected void startCameraActivity() {
        File file = new File(_path);
        Uri outputFileUri = Uri.fromFile(file);

        final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

        startActivityForResult(intent, 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        Log.i(TAG, "resultCode: " + resultCode);

        if (resultCode == -1) {
            onPhotoTaken();
        } else {
            Log.v(TAG, "User cancelled");
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putBoolean(SimpleAndroidOCRActivity.PHOTO_TAKEN, _taken);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        Log.i(TAG, "onRestoreInstanceState()");
        if (savedInstanceState.getBoolean(SimpleAndroidOCRActivity.PHOTO_TAKEN)) {
            onPhotoTaken();
        }
    }

    protected void onPhotoTaken() {
        _taken = true;

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 4;

        Bitmap bitmap = BitmapFactory.decodeFile(_path, options);

        try {
            ExifInterface exif = new ExifInterface(_path);
            int exifOrientation = exif.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_NORMAL);

            Log.v(TAG, "Orient: " + exifOrientation);

            int rotate = 0;

            switch (exifOrientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotate = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotate = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotate = 270;
                break;
            }

            Log.v(TAG, "Rotation: " + rotate);

            if (rotate != 0) {

                // Getting width & height of the given image.
                int w = bitmap.getWidth();
                int h = bitmap.getHeight();

                // Setting pre rotate
                Matrix mtx = new Matrix();
                mtx.preRotate(rotate);

                // Rotating Bitmap
                bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
            }

            // Convert to ARGB_8888, required by tess
            bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);

        } catch (IOException e) {
            Log.e(TAG, "Couldn't correct orientation: " + e.toString());
        }

        // _image.setImageBitmap( bitmap );

        Log.v(TAG, "Before baseApi");

        TessBaseAPI baseApi = new TessBaseAPI();
        baseApi.setDebug(true);
        baseApi.init(DATA_PATH, lang, TessBaseAPI.OEM_CUBE_ONLY);
        baseApi.setImage(bitmap);

        String recognizedText = baseApi.getUTF8Text();

        baseApi.end();

        // You now have the text in recognizedText var, you can do anything with it.
        // We will display a stripped out trimmed alpha-numeric version of it (if lang is eng)
        // so that garbage doesn't make it to the display.

        Log.v(TAG, "OCRED TEXT: " + recognizedText);

        if ( lang.equalsIgnoreCase("eng") ) {
            recognizedText = recognizedText.replaceAll("[^a-zA-Z0-9]+", " ");
        }

        recognizedText = recognizedText.trim();

        if ( recognizedText.length() != 0 ) {
            _field.setText(_field.getText().toString().length() == 0 ? recognizedText : _field.getText() + " " + recognizedText);
            _field.setSelection(_field.getText().toString().length());
        }

        // Cycle done.
    }

    // www.Gaut.am was here
    // Thanks for reading!
}

My LogCat as following

07-29 14:04:03.028: I/Choreographer(601): Skipped 36 frames!  The application may be doing too much work on its main thread.
07-29 14:04:03.355: D/dalvikvm(601): Added shared lib /data/data/com.project.ocrutilityv4/lib/liblept.so 0x411e7cb8
07-29 14:04:03.355: D/dalvikvm(601): Trying to load lib /data/data/com.project.ocrutilityv4/lib/libtess.so 0x411e7cb8
07-29 14:04:04.735: D/dalvikvm(601): Added shared lib /data/data/com.project.ocrutilityv4/lib/libtess.so 0x411e7cb8
07-29 14:04:06.595: A/libc(601): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 719 (AsyncTask #1)
07-29 14:04:10.515: I/Choreographer(601): Skipped 948 frames!  The application may be doing too much work on its main thread.
07-29 14:04:12.666: E/Trace(728): error opening trace file: No such file or directory (2)
07-29 14:04:13.555: W/Resources(728): Converting to int: TypedValue{t=0x3/d=0x35 "1900" a=2 r=0x7f06000f}
07-29 14:04:13.555: W/Resources(728): Converting to int: TypedValue{t=0x3/d=0x35 "1900" a=2 r=0x7f06000f}
07-29 14:04:22.065: D/dalvikvm(728): GC_CONCURRENT freed 123K, 3% free 8331K/8519K, paused 80ms+95ms, total 352ms
07-29 14:04:22.886: I/Choreographer(728): Skipped 32 frames!  The application may be doing too much work on its main thread.
07-29 14:04:22.945: D/gralloc_goldfish(728): Emulator without GPU emulation detected.

I added following in tessdata folder But it’s not helpful for me.:(

 ara.cube.bigrams
 ara.cube.fold
 ara.cube.lm
 ara.cube.nn
 ara.cube.params
 ara.cube.size
 ara.cube.word-freq
 ara.traineddata

without ocrEngineMode = TessBaseAPI.OEM_TESSERACT_CUBE_COMBINED my application run fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:28:51+00:00Added an answer on June 8, 2026 at 6:28 pm

    I have founded error in my code that’s is as following.

    public static final String lang = “ara”;
    //(not) public static final String lang = “eng”;

    Then above code is perfect running after adding following file into assets/tessdata folder.

     ara.cube.bigrams
     ara.cube.fold
     ara.cube.lm
     ara.cube.nn
     ara.cube.params
     ara.cube.size
     ara.cube.word-freq
     ara.traineddata
    

    Thanks to all who’s reply me and help me.:)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i want to use a texture on a cube (created by glutsolidcube()), how
I want use this 1 for using Bar code or QR code scanner. I
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want use JQuery mobile for the front-end of my mobile application, but I
I don't want use old Visual Basic methods in my code, and I'm confused
I just build my fist LED cube and want to expand the test code
I want use a typedef struct that isn't already defined, but it is later.
I want use the Scintilla controls and the RadControls for Winforms, but I do
I want use ORDER BY RAND() query mysql. But I have some question want
I need to use HTML comments to store specific data, but I don't want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.