/// <summary> /// Takes an image, and runs it through Tesseract, returning /// the cleaned string it detected. /// </summary> /// <returns>The ocr.</returns> /// <param name="image">Image.</param> private async Task <string[]> ProcessOCR(UIImage image) { if (!_tesseractInitialised) { //tesseract.SetPageSegmentationMode(PageSegmentationMode.SingleWord); _tesseractInitialised = await tesseract.Init("eng"); tesseract.SetVariable("tosp_min_sane_kn_sp", "10"); if (!string.IsNullOrEmpty(OCRWhiteList)) { tesseract.SetWhitelist(OCRWhiteList); } } bool success = await tesseract.SetImage(image.AsPNG().AsStream()); if (!isDisposing) { if (success) { var results = tesseract.Results(PageIteratorLevel.Word); return(results?.Select(u => u.Text).ToArray()); } } return(null); }
public async void Sample4JpgWithSetVariable() { await _api.Init("eng"); _api.SetVariable("tessedit_char_whitelist", "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 Sample4JpgWithSetVariable() { await _api.Init("eng"); _api.SetVariable("tessedit_char_whitelist", "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); } }