Android Example OCR OFFLINE - Tesseract

joilts

Member
Licensed User
Longtime User
Now you have to train your Tesseract and create your on font file to use at your app.
 

roberto64

Active Member
Licensed User
Longtime User
Now you have to train your Tesseract and create your on font file to use at your app.
hi, I used VietOCR.NET to understand what kind of fomato Tesseract OCR could recognize both letters and numbers, I made a crop the image and tried to make it recognize OCR, sarebe this what you say? or you must also make a Piccalo rutin like this (var = srcImage1 System.Drawing.Image.FromFile (@ "D: \ Image \ font_english.jpg");
var newWidth1 = (int) (srcImage1.Width * 2);
var newHeight1 = (int) (srcImage1.Height * 2);

var image = new Bitmap (srcImage1, new Size (newWidth1, newHeight1));
Tesseract OCR var = new ();

ocr.Init (@ "D: \ OCRTEST \ tessdata \", "eng", false);
ocr.SetVariable ("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-0123456789 '?.; =, ()");
var result = ocr.DoOCR (image, Rectangle.Empty);
foreach (Word word in result)
{
Response.Write (word.Text + "");

})
Greetings
 

roberto64

Active Member
Licensed User
Longtime User
Hi, I do not understand why passing a Bitmap image within the function as described below, by mistake, I would like to go directly to the Bitmap image and not save the image first and then view it.
regards
B4X:
Dim path As Bitmap
        Dim retStr As String = ""
        retStr = NativeMe.RunMethod("getText",  Array (path,File.DirRootExternal))

#AdditionalJar: javacpp-presets-bin\javacpp
#AdditionalJar: javacpp-presets-bin\tesseract-android-arm
#AdditionalJar: javacpp-presets-bin\leptonica-android-arm
#AdditionalJar: javacpp-presets-bin\tesseract
#AdditionalJar: javacpp-presets-bin\leptonica

'public static String getText(String path, String filename, String extension, String TrainFileDir)
#If JAVA
import org.bytedeco.javacpp.*;
import static org.bytedeco.javacpp.lept.*;
import static org.bytedeco.javacpp.tesseract.*;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;


private TessBaseAPI tessBaseAPI;
//public static String getText(String path, String filename, String extension, String TrainFileDir)
public static String getText(Bitmap path, String TrainFileDir) {
    BA.Log("" + "Here - getText() ");
    BytePointer outText;
    TessBaseAPI api = new TessBaseAPI();
    BA.Log("" + "Before Init ");
    int retCode = api.Init(TrainFileDir, "eng");
    BA.Log("directori =" + TrainFileDir);
    BA.Log("RETCODE =" + retCode);
    if (retCode != 0) {
        return("Could not initialize tesseract.");
    }
  
    PIX image = pixRead(Bitmap);
    BA.Log("" + "File Open");
    api.SetImage(image);
    BA.Log("" + "Before get Text");
    outText = api.GetUTF8Text();
    api.End();
    outText.deallocate();
    pixDestroy(image);
    return(outText.getString());

}
#End If
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…