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; } } }
public async void Sample1JpgRectangle() { await _api.Init("eng"); using (var stream = LoadSample("sample1.jpg")) { _api.SetRectangle(new Rectangle(0, 0, 900, 100)); var result = await _api.SetImage(stream); Assert.IsTrue(result); Assert.AreEqual("The quick brown fox\n\n", _api.Text); var data = _api.Results(PageIteratorLevel.Block).ToList(); Assert.AreEqual(1, data.Count); Assert.AreEqual("The quick brown fox\n\n", data [0].Text); data = _api.Results(PageIteratorLevel.Paragraph).ToList(); Assert.AreEqual(1, data.Count); Assert.AreEqual("The quick brown fox\n\n", data [0].Text); } }