예제 #1
0
        private void TransparentForm_MouseMove(object sender, MouseEventArgs e)
        {
            var imageCapture = new ImageCapture();
            var ocr          = new OCR()
            {
                Language = "por"
            };
            var speech    = new Speech();
            var filePath  = String.Empty;
            var imageText = String.Empty;

            filePath      = imageCapture.Capture(new Point(MousePosition.X - 20, MousePosition.Y - 10));
            ocr.ImagePath = filePath;

            imageText = ocr.FromImage();
            Console.WriteLine(imageText);
            speech.FromText(imageText);
        }
예제 #2
0
        /// <summary>Extrai todas as imagens de um arquivo PDF.</summary>
        public string ExtractImage(string filePath, string language)
        {
            var tesseract = new OCR()
            {
                Language = language
            };
            var imagePath = String.Empty;
            var imageText = String.Empty;

            using (var reader = new PdfReader(filePath))
            {
                var parser   = new PdfReaderContentParser(reader);
                var listener = new ImageRenderListener();

                for (var index = 1; index <= reader.NumberOfPages; index++)
                {
                    parser.ProcessContent(index, listener);

                    if (listener.Images.Count > 0)
                    {
                        for (int count = 0; count < listener.Images.Count; count++)
                        {
                            imagePath           = System.IO.Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory) + "temp.png";
                            tesseract.ImagePath = imagePath;
                            imageText          += tesseract.FromImage();
                        }
                    }
                }

                if (!String.IsNullOrWhiteSpace(imagePath))
                {
                    File.Delete(imagePath);
                }

                return(imageText);
            }
        }