private async Task _GetText(Bitmap cropped) { if (!TesseractApi.Initialized) { await TesseractApi.Init("eng"); } TesseractApi.SetRectangle(new Tesseract.Rectangle((int)(cropped.Width * 0.24), 10, (int)(cropped.Width * 0.35), (int)(cropped.Height * 0.065))); TesseractApi.SetWhitelist("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); if (await TesseractApi.SetImage(File.OpenRead(Path.ChangeExtension(ImagePath, "card")))) { string s = TesseractApi.Text; if (Name == "" || Name == "NO TEXT DETECTED") { if (s != "") { if (s != "" && s[0].ToString() == s[0].ToString().ToLower()) { s = s.Substring(1, s.Length - 1); } TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; s = textInfo.ToTitleCase(s.ToLower()); } else { s = "NO TEXT DETECTED"; } Name = s; } } }
async Task <TesseractApi> InitaliazeApi() { var api = new TesseractApi(this.Context, AssetsDeployment.OncePerVersion); await api.Init("ocrb"); api.SetWhitelist("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789<"); api.Progress += ScanProgress; return(api); }
public async void Sample4JpgWithWhitelist() { await _api.Init("eng"); _api.SetWhitelist("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); using (var stream = LoadSample("sample4.jpg")) { var result = await _api.SetImage(stream); Assert.IsTrue(result); Assert.IsTrue(_api.Text.Contains("Good font for the OCR")); } }
public async void Sample4JpgWithWhitelist() { await _api.Init("eng"); _api.SetWhitelist("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); using (var stream = LoadSample("sample4.jpg")) { var result = await _api.SetImage(stream); Assert.IsTrue(result); Assert.AreEqual( "Good font for the OCR\nDingufrfom n Me am\nhe mm mm m cm\n\nGood 60m size for ocn\n\n", _api.Text); } }
private void Initialize() { _tesseractApi = new TesseractApi(Context, AssetsDeployment.OncePerVersion); setWhitelist = new CallOnce(() => { _tesseractApi.SetWhitelist("あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめももやゆよらりるれろわゐゑをがぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽんアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン"); }); currentText = string.Empty; SetBackgroundColor(Color.White); _path = new Path(); _mPaint = new Paint { Dither = true, Color = Color.Black, StrokeJoin = Paint.Join.Round, StrokeCap = Paint.Cap.Round, StrokeWidth = 15 }; _mPaint.SetStyle(Paint.Style.Stroke); _tesseractApi.Init("jpn"); }
public async Task <Tuple <string, ImageSource> > AndroidTesseractStart(ImageSource image) { Context context = Android.App.Application.Context; string result = ""; ImageSource resultImg = image; // Default try { string whitelist = "01234556789"; whitelist += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; whitelist += "abcdefghijklmnopqrstuvwxyz"; TesseractApi api = new TesseractApi(context, AssetsDeployment.OncePerInitialization); await api.Init("eng"); api.SetWhitelist(whitelist); Bitmap bitmap = await GetBitmapFromImageSourceAsync(image, context); //ImageSource -> Bitmap Bitmap rebitmap = BitMapWidthCutting(bitmap); //BitMap Width cut in half rebitmap = BitMapLineDelete(rebitmap, 2); //BitMap Line Delete //BitMapChack(rebitmap); //Console Write BitMap resultImg = BMPtoImgsource(rebitmap); // BitMap -> ImageSource byte[] bitmapData = ConvertBitmapToByte(rebitmap); //BitMap - > Byte[] bool success = await api.SetImage(bitmapData); if (success) { result = api.Text; } return(Tuple.Create(result, resultImg)); }catch (Exception e) { return(Tuple.Create(e.Message, resultImg));; } }