public string Recognize(Image img, OCROutputType outputType) { string str; try { string str1 = ""; if (img.get_PixelFormat() != 196865) { str1 = (outputType != OCROutputType.HOCR ? this.tp.Apply(img, false) : this.tp.Apply(img, true)); } else { Bitmap bitmap = new Bitmap(img.get_Width(), img.get_Height(), 139273); bitmap.SetResolution(img.get_HorizontalResolution(), img.get_VerticalResolution()); Graphics graphic = Graphics.FromImage(bitmap); graphic.DrawImageUnscaled(img, 0, 0); graphic.Dispose(); str1 = (outputType != OCROutputType.HOCR ? this.tp.Apply(bitmap, false) : this.tp.Apply(bitmap, true)); bitmap.Dispose(); } str = str1; } catch { return ""; } return str; }
public string Recognize(string filePath, OCROutputType outputType) { string str; try { if (outputType != OCROutputType.HOCR) { this.tp.SetVariable("tessedit_create_hocr", "false"); } else { this.tp.SetVariable("tessedit_create_hocr", "true"); } str = this.tp.Apply(filePath); } catch { return ""; } return str; }