3

I am working on an app where i need to identify text from an image and what could be the better way than using Tesseract. As Tesseract is an open source and widely accepted. I have used Tesseract in my app. So, i am getting images from user and then applying 2-3 operations on image to improve chances of getting result but i am not getting expected result.

Java Code ->

    final Bitmap tessBitmap = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(tessBitmap);
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    canvas.drawBitmap(image, 0, 0, paint);

    Mat tessMat = new Mat();

    Utils.bitmapToMat(tessBitmap, tessMat);

    Imgproc.cvtColor(tessMat, tessMat, Imgproc.COLOR_RGB2GRAY);

    Imgproc.threshold(tessMat, tessMat, 0, 255, Imgproc.THRESH_BINARY + Imgproc.THRESH_OTSU);

    final Bitmap newTessBitmap = Bitmap.createBitmap(tessMat.width(), tessMat.height(), Bitmap.Config.RGB_565);

    Utils.matToBitmap(tessMat, newTessBitmap);

    final Bitmap finalTessBitmap = Bitmap.createBitmap(newTessBitmap.getWidth(), newTessBitmap.getHeight(), Bitmap.Config.ARGB_8888);

    Canvas tessCanvas = new Canvas(finalTessBitmap);
    Paint tessPaint = new Paint();
    tessPaint.setColor(Color.BLACK);
    tessCanvas.drawBitmap(newTessBitmap, 0, 0, tessPaint);

and then passing this bitmap to tesseract to get output but not getting efficient and sometimes i dont even get anything in output. I have compared my result with one online website https://www.newocr.com/ .

Which is also using tesseract in back end as it is claiming. i have also tried to contact them via email but coudlnt get anything from them.

mTess = new TessBaseAPI();
tessModelPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/tesseract/";
mTess.init(tessModelPath, "eng", TessBaseAPI.OEM_TESSERACT_ONLY);                                 mTess.setPageSegMode(TessBaseAPI.PageSegMode.PSM_AUTO);
mTess.setImage(finalTessBitmap);

This is the base Tesseract code. Please help me solve my issue. Thanks...

Given below is the image i get after applying above mentioned operation but when i pass it to tesseract i did not get anything but when passing to newocr.com website it is producing exact text.

Image

Result from newOcr.

This image is for results.

Check this image for results.

Please suggest me about what to do if you have any idea.

After Digging more and running the same image in python code i have found out that in python pytesseract it works like charm and producing exact output as newocr. But when i run in android it doesnt work that well. so may be the issue is with API of Tesseract. So, now if you know anything still which i can do to improve accuracy. Help me. Thanks in Advance.

Karsh Soni
  • 51
  • 4
  • Thanks for your response @JimGrigoryan i also got surprised with their results and that is why i mailed them for what kind of image processing they do? but could'nt get anything. And i know that there are api available but i want to implement this offline. so i just want to know how can i improve the results. thanks. – Karsh Soni Mar 12 '19 at 11:02

1 Answers1

1
$ tesseract 8UIBw.jpg -
Warning: Invalid resolution 0 dpi. Using 70 instead.
Estimating resolution as 613
Tillamook

It was without any preprocessing...

$ tesseract -v
tesseract 4.0.0-253-g3948
 leptonica-1.76.0 (Dec 14 2018, 15:34:47) [MSC v.1916 LIB Release x64]
  libgif 5.1.4 : libjpeg 9b : libpng 1.6.35 : libtiff 4.0.9 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.3.0
 Found AVX
 Found SSE
user898678
  • 2,994
  • 2
  • 18
  • 17
  • Could you please elaborate your answer as i couldnt understand what you are trying to say? @user898678 – Karsh Soni Mar 13 '19 at 06:12
  • 2
    It was reaction for "Please suggest me about what to do if you have any idea." and "I doubt newocr is using Tesseract as they claim." - tesseract version 4 process it without any preprocessing. – user898678 Mar 13 '19 at 17:37
  • I have also observed same thing when i tried to run in python. Now i need something which can either optimize library or some image processing which will be needed for Tess-Two to produce Accurate Output. – Karsh Soni Mar 20 '19 at 12:35