public SearchOptions(string path, string keyword, RecognitionPrecision selectedPrecisionOCR, RecognitionLanguage selectedLanguageOCR, bool caseSensitive, bool useOCR, bool useSubfolders, bool usePDF, bool useDOCX, bool useODT) { Path = path; Keyword = keyword; SelectedPrecisionOCR = selectedPrecisionOCR; SelectedLanguageOCR = selectedLanguageOCR; CaseSensitive = caseSensitive; UseOCR = useOCR; UseSubfolders = useSubfolders; UsePDF = usePDF; UseDOCX = useDOCX; UseODT = useODT; }
string ImageToText(byte[] imageBytes, RecognitionLanguage rl, RecognitionPrecision rp) { try { using var engine = new TesseractEngine(@"./Files", _optionService.TranslateLanguage(rl), EngineMode.Default); using var img = _optionService.TranslatePrecision(rp).Item4 == System.Drawing.Imaging.ImageFormat.Tiff ? Pix.LoadTiffFromMemory(imageBytes) : Pix.LoadFromMemory(imageBytes); using var pager = engine.Process(img); return(pager.GetText().ToString()); //System.Diagnostics.Debug.WriteLine("Mean confidence: {0}", pager.GetMeanConfidence()); //System.Diagnostics.Debug.WriteLine("Text {0}", text); } catch (Exception ee) { System.Diagnostics.Debug.WriteLine("Unexpected Error: " + ee.Message); System.Diagnostics.Debug.WriteLine("Details: "); System.Diagnostics.Debug.WriteLine(ee.ToString()); } return(""); }
public (PageDimensions, RenderFlags, PixelFormat, ImageFormat) TranslatePrecision(RecognitionPrecision rp) { return rp switch { RecognitionPrecision.High or RecognitionPrecision.Default => (new PageDimensions(1080, 1920), RenderFlags.RenderAnnotations, PixelFormat.Format32bppArgb, ImageFormat.Png), RecognitionPrecision.Medium => (new PageDimensions(720, 1280), RenderFlags.RenderAnnotations, PixelFormat.Format32bppArgb, ImageFormat.Jpeg), RecognitionPrecision.Low => (new PageDimensions(720, 1280), RenderFlags.RenderAnnotations | RenderFlags.OptimizeTextForLcd | RenderFlags.Grayscale, PixelFormat.Format32bppRgb, ImageFormat.Bmp), _ => (new PageDimensions(1080, 1920), RenderFlags.RenderAnnotations, PixelFormat.Format32bppArgb, ImageFormat.Png), }; }