Algorithmix.Forensics.OCR.Recognize C# (CSharp) Method

Recognize() public static method

Execute OCR on a given image, this static member will process the image, Safely open, execute and dispose a Tesseract Object and store the result in a new OcrData object.
public static Recognize ( Bitmap original, Accuracy mode = Accuracy.High, string lang = "eng", bool enableTimer = false ) : OcrData
original System.Drawing.Bitmap Image to be OCR-ed
mode Accuracy Accuracy setting
lang string Language of text for OCR Language Model
enableTimer bool Measure the Scantime for Diagnostic purposes
return OcrData
        public static OcrData Recognize(Bitmap original,
            Accuracy mode = Accuracy.High,
            string lang = "eng",
            bool enableTimer = false)
        {
            Image<Bgra, byte> img = new Image<Bgra, byte>(original);
            Image<Gray, byte> processed;
            Tesseract.Charactor[] chars;
            String text;
            long confidence;
            long scantime = Int64.MinValue;
            using (OCR ocr = new OCR(mode, lang, enableTimer))
            {
                processed = ocr.Preprocess(img);
                ocr.Scan(processed);
                confidence = ocr.OverallCost();
                chars = ocr.Charactors();
                text = ocr.Text();
                if (enableTimer)
                {
                    scantime = ocr.Elapsed();
                    ocr.Stop();
                }
            }
            img.Dispose();
            if (scantime == Int64.MinValue)
            {
                return new OcrData(processed, chars, text, confidence);
            }
            return new OcrData(processed, chars, text, confidence, scantime);
        }