Exemple #1
0
        public static List <Line> ExtractLinesFromImage(Image image)
        {
            List <Line> result = new List <Line>();

            string resourceRoot = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);

            resourceRoot = resourceRoot.Substring(6);

            using (Ocr ocrEngine = new Ocr(resourceRoot)) {
                try {
                    Bitmap    bitmap    = new Bitmap(image);
                    OcrParams ocrParams = new OcrParams {
                        CheckOrientation = true,
                        Language         = Language.English
                    };

                    OcrResults ocrResults = ocrEngine.Recognize(bitmap, ocrParams);

                    using (var graphics = Graphics.FromImage(bitmap)) {
                        foreach (var region in ocrResults.Regions)
                        {
                            foreach (var line in region.Lines)
                            {
                                result.Add(line);
                            }
                        }
                    }
                } catch (Exception ex) {
                    Trace.WriteLine(ex.Message);
                }
            }

            return(result);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // Code usage sample
            Ocr ocr = new Ocr();

            using (Bitmap bmp = new Bitmap(@"C:\temp\test.bmp"))
            {
                tessnet2.Tesseract tessocr = new tessnet2.Tesseract();
                tessocr.Init(@"C:\Users\mkmak\Documents\Visual Studio 2013\Projects\ConsoleApplication1\tessdata", "eng", false);
                tessocr.GetThresholdedImage(bmp, Rectangle.Empty).Save("c:\\temp\\" + Guid.NewGuid().ToString() + ".bmp");
                // Tessdata directory must be in the directory than this exe
                //Console.WriteLine("Multithread version");
                //ocr.DoOCRMultiThred(bmp, "eng");
                Console.WriteLine("Normal version");
                ocr.DoOCRNormal(bmp, "eng");
            }
            Thread.Sleep(100000);
        }