public string GetUtf8Text(ICImage image) { if (image == null) { return(""); } _tesseracts[_currentLanguages].SetImage(image.GetAfterProcessImage()); return(_tesseracts[_currentLanguages].GetUTF8Text()); }
public List <Dictionary <string, string> > GetUtf8TextBaseOnRegions(ICImage image, ROIProfile regions, out IImage imgdrawed) { imgdrawed = null; List <Dictionary <string, string> > result = new List <Dictionary <string, string> >(); if (image == null) { return(result); } if (regions == null) { return(result); } IPaperResource paperResource = PaperResource.DefaultInstance(); PaperProfile paperProfile = paperResource.GetPaperProfile(regions.PaperSize); if (paperProfile == null) { return(result); } InitialLaguagePack(regions); Dictionary <string, string> onePage = new Dictionary <string, string>(); Image <Gray, byte> imgThre = image.GetAfterProcessImage() as Image <Gray, byte>; Image <Bgr, byte> imgTmp = imgThre.Copy().Convert <Bgr, byte>(); foreach (ROI region in regions.Regions) { Rectangle rect = region.RegionRectangle.ConvertActualyImageSizeToImageResize(paperProfile, imgThre.Bitmap); imgThre.ROI = rect; imgTmp.Draw(rect, new Bgr(Color.Red), 1); _tesseracts[region.Language].SetImage(imgThre.Copy()); string txt = _tesseracts[region.Language].GetUTF8Text(); MatchCollection ms = Regex.Matches(txt, region.GenaratedRegexPattern, RegexOptions.Multiline); Match m = ms.Cast <Match>().OrderByDescending(s => s.Length).Take(1).FirstOrDefault(); onePage.Add(region.RegionName, m?.Value); imgThre.ROI = Rectangle.Empty; } imgdrawed = imgTmp; result.Add(onePage); return(result); }