Esempio n. 1
0
 public ScreenReader()
 {
     Ocr = new OCR.TesseractWrapper.TesseractProcessor();
     //Ocr.Init(@"tessdata\", "sc2", 3);
     Ocr.Init(ocr_path, "sc2", 3);
     Ocr.SetPageSegMode(OCR.TesseractWrapper.ePageSegMode.PSM_SINGLE_WORD);
 }
Esempio n. 2
0
        public override SFWorkflow.WFState Run()
        {
//			System.IO.FileStream fs = System.IO.File.Open(this.FileToProcess, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
//     byte [] inByte = new byte[fs.Length];
//    fs.Read(inByte, 0, inByte.Length);
//      fs.Close();

//			Image imgInFile = Image.FromStream(new System.IO.MemoryStream(inByte));
//			System.IO.MemoryStream myTempStream = new System.IO.MemoryStream();
//			imgInFile.Save( myTempStream, System.Drawing.Imaging.ImageFormat.Tiff);

            SFWorkflow.WFState retval = new SFWorkflow.WFState();

//			System.Drawing.Image image = null;

            try
            {
                foreach (System.Drawing.Image image in GetImageList(this.FileToProcess))
                {
                    //				image = new System.Drawing.Bitmap(this.FileToProcess);
                    // deskew the image
                    gmseDeskew deskew         = new gmseDeskew((System.Drawing.Bitmap)image);
                    double     imageSkewAngle = deskew.GetSkewAngle();

//					if ((imageSkewAngle > MINIMUM_DESKEW_THRESHOLD || imageSkewAngle < -(MINIMUM_DESKEW_THRESHOLD)))
//						image = ImageHelper.Rotate(image, imageSkewAngle);

                    OCR.TesseractWrapper.TesseractProcessor tessocr = new OCR.TesseractWrapper.TesseractProcessor();
                    try
                    {
                        string tessdata = System.IO.Path.Combine(basedir, TESSDATA);

                        StringBuilder sb = new StringBuilder();
                        if (true == tessocr.Init(tessdata, "eng", (int)OCR.TesseractWrapper.ePageSegMode.PSM_AUTO))
                        {
                            string prevword = string.Empty;
                            OCR.TesseractWrapper.DocumentLayout dl = tessocr.AnalyseLayout((System.Drawing.Bitmap)image);
#if false
                            foreach (OCR.TesseractWrapper.Block block in dl.Blocks)
                            {
                                foreach (OCR.TesseractWrapper.Paragraph paragraph in block.Paragraphs)
                                {
                                    foreach (OCR.TesseractWrapper.TextLine line in paragraph.Lines)
                                    {
                                        foreach (OCR.TesseractWrapper.Word word in line.Words)
                                        {
                                            System.Drawing.Rectangle part = new Rectangle(word.Left, word.Top, word.Right - word.Left + 1, word.Bottom - word.Top + 1);
                                            tessocr.UseROI = true;
                                            tessocr.ROI    = part;
                                            string recognizedword = tessocr.Recognize(image).Replace("\n", "");
                                            recognizedword = System.Text.RegularExpressions.Regex.Replace(recognizedword, @"[^\w\.@-]", string.Empty);
                                            prevword       = recognizedword;
                                        }
                                    }
                                    sb.Append("\n");
                                }
                                sb.Append("\n");
                            }
#endif
                        }
                    }
                    catch (Exception ex)
                    {
                        WFLogger.NLogger.ErrorException("ERROR: Could not instantiate TesseractProcessor.", ex);
                    }
                }
            }
            catch (Exception ex)
            {
                WFLogger.NLogger.ErrorException("ERROR: GetImageList failed.", ex);
            }
            finally
            {
//				if (image != null)
//					image.Dispose();
            }

            retval.Value = SFWorkflow.WFState.WFStateSuccess;

            return(retval);
        }