Ejemplo n.º 1
0
        public static OcrData RunOCR(Bitmap inputImage, OcrPageMode pageSegMode)
        {
            OcrData OcrData1 = new OcrData();

            using (var ocrEngine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default))
            {
                ocrEngine.SetVariable("tessedit_char_whitelist", @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$/.&");
                ////ocrEngine.SetVariable("language_model_penalty_non_freq_dict_word", "0");
                ////ocrEngine.SetVariable("language_model_penalty_non_dict_word", "0");
                ////ocrEngine.SetVariable("tessedit_char_blacklist", "");
                ////ocrEngine.SetVariable("classify_bln_numeric_mode", "1");
                //BitmapToPixConverter b2p = new BitmapToPixConverter();
                //Pix nPic = b2p.Convert(inputImage);
                //nPic = nPic.ConvertRGBToGray(255, 255, 255);
                //nPic.BinarizeSauvola(120, (float)0.35, false);


                using (var ocrPage = ocrEngine.Process(inputImage, (PageSegMode)pageSegMode))
                {
                    //ocrPage.AnalyseLayout();

                    //ocrPage.GetThresholdedImage().Save(@"D:\\ocrd_image.jpg", ImageFormat.Default);
                    ROI OcrRoi = new ROI();
                    OcrRoi.X1               = ocrPage.RegionOfInterest.X1;
                    OcrRoi.Y1               = ocrPage.RegionOfInterest.Y1;
                    OcrRoi.X2               = ocrPage.RegionOfInterest.X2;
                    OcrRoi.Y2               = ocrPage.RegionOfInterest.Y2;
                    OcrRoi.Height           = ocrPage.RegionOfInterest.Height;
                    OcrRoi.Width            = ocrPage.RegionOfInterest.Width;
                    OcrData1.ReadText       = ocrPage.GetText();
                    OcrData1.LineConfidence = (int)ocrPage.GetMeanConfidence();
                }
            }
            return(OcrData1);
        }
Ejemplo n.º 2
0
        public static OcrData RunOCR(Bitmap inputImage, OcrPageMode pageSegMode)
        {
            OcrData OcrData1 = new OcrData();
            using (var ocrEngine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default))
            {
                ocrEngine.SetVariable("tessedit_char_whitelist", @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$/.&");
                ////ocrEngine.SetVariable("language_model_penalty_non_freq_dict_word", "0");
                ////ocrEngine.SetVariable("language_model_penalty_non_dict_word", "0");
                ////ocrEngine.SetVariable("tessedit_char_blacklist", "");
                ////ocrEngine.SetVariable("classify_bln_numeric_mode", "1");
                //BitmapToPixConverter b2p = new BitmapToPixConverter();
                //Pix nPic = b2p.Convert(inputImage);
                //nPic = nPic.ConvertRGBToGray(255, 255, 255);
                //nPic.BinarizeSauvola(120, (float)0.35, false);

                using (var ocrPage = ocrEngine.Process(inputImage,(PageSegMode)pageSegMode))
                {
                    //ocrPage.AnalyseLayout();

                    //ocrPage.GetThresholdedImage().Save(@"D:\\ocrd_image.jpg", ImageFormat.Default);
                    ROI OcrRoi = new ROI();
                    OcrRoi.X1 = ocrPage.RegionOfInterest.X1;
                    OcrRoi.Y1 = ocrPage.RegionOfInterest.Y1;
                    OcrRoi.X2 = ocrPage.RegionOfInterest.X2;
                    OcrRoi.Y2 = ocrPage.RegionOfInterest.Y2;
                    OcrRoi.Height = ocrPage.RegionOfInterest.Height;
                    OcrRoi.Width = ocrPage.RegionOfInterest.Width;
                    OcrData1.ReadText = ocrPage.GetText();
                    OcrData1.LineConfidence = (int)ocrPage.GetMeanConfidence();

                }

            }
            return OcrData1;
        }