Exemplo n.º 1
0
        private void loadImageButton_Click(object sender, EventArgs e)
        {
            if (openImageFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Bgr drawColor = new Bgr(Color.Blue);
                try
                {
                    Image <Bgr, Byte> image = new Image <Bgr, byte>(openImageFileDialog.FileName);

                    using (Image <Gray, byte> gray = image.Convert <Gray, Byte>())
                    {
                        _ocr.Recognize(gray);
                        Tesseract.Charactor[] charactors = _ocr.GetCharactors();
                        foreach (Tesseract.Charactor c in charactors)
                        {
                            image.Draw(c.Region, drawColor, 1);
                        }

                        imageBox1.Image = image;

                        //String text = String.Concat( Array.ConvertAll(charactors, delegate(Tesseract.Charactor t) { return t.Text; }) );
                        String text = _ocr.GetText();
                        ocrTextBox.Text = text;
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // _ocr = new Tesseract("tessdata", "eng", Tesseract.OcrEngineMode.OEM_TESSERACT_CUBE_COMBINED);
            try
            {
                var image = new Image <Bgr, byte>("IMAG0277.jpg");

                using (Image <Gray, byte> gray = image.Convert <Gray, Byte>())
                {
                    _ocr.Recognize(gray);
                    Tesseract.Charactor[] charactors = _ocr.GetCharactors();

                    //String text = String.Concat( Array.ConvertAll(charactors, delegate(Tesseract.Charactor t) { return t.Text; }) );
                    String text = _ocr.GetText();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }