예제 #1
0
        private void vision_KeyTestButton_Click(object sender, EventArgs e)
        {
            string tempKey = Program.Settings.KeyInfo.Key;

            try
            {
                Program.Settings.KeyInfo.Key = vision_KeyTextBox.Text;

                Rectangle rect = new Rectangle(0, 0, 300, 100);

                using (Bitmap image = new Bitmap(rect.Width, rect.Height))
                    using (Graphics graphics = Graphics.FromImage(image))
                        using (Font font = new Font("Arial", 50))
                        {
                            graphics.Clear(Color.White);

                            graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                            graphics.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                            graphics.TextRenderingHint = TextRenderingHint.AntiAlias;

                            StringFormat sf = new StringFormat();
                            sf.LineAlignment = StringAlignment.Center;
                            sf.Alignment     = StringAlignment.Center;
                            graphics.DrawString("Hello", font, Brushes.Black, rect, sf);

                            string tempPath = OcrHelper.GetTempPath(".png");

                            try
                            {
                                image.Save(tempPath);
                                OcrEngine engine = OcrEngine.Create(OcrEngineType.GoogleVision);
                                OcrResult result = engine.LoadFile(tempPath, "en");
                                MessageBox.Show(this,
                                                "Result: " + result.ResultType + Environment.NewLine +
                                                (string.IsNullOrEmpty(result.Text) ? string.Empty : "Text: " + result.Text + Environment.NewLine) +
                                                (string.IsNullOrEmpty(result.Error) ? string.Empty : "Error:" + result.Error));
                            }
                            finally
                            {
                                try
                                {
                                    File.Delete(tempPath);
                                }
                                catch { }
                            }
                        }
            }
            finally
            {
                Program.Settings.KeyInfo.Key = tempKey;
            }
        }
예제 #2
0
파일: MainForm.cs 프로젝트: radtek/Ocr
        private void RunOcr()
        {
            if (ocrImagePanel.Image != null && ocrImagePanel.SelectionImage != null && ocrImagePanel.SelectionImage.Width > 0 && ocrImagePanel.SelectionImage.Height > 0)
            {
                using (Image processedImage = ProcessImage(ocrImagePanel.SelectionImage, Program.ActiveOcrProfileIndex))
                {
                    OcrHelper.Ocr(processedImage);
                }

                /*using (Image processedImage = ProcessImage(ocrImagePanel.SelectionImage, Program.ActiveOcrProfileIndex))
                 * {
                 *  originalRichTextBox.Parent.BackColor = Color.DodgerBlue;
                 *  processedImage.Save("C:/ocr_tmp.png");
                 *  OcrResult result = Program.ActiveOcrEngine.LoadFile("C:/ocr_tmp.png", Program.ActiveLanguageFrom);
                 *  if (result.Succes)
                 *  {
                 *      originalRichTextBox.Text = result.Text;
                 *  }
                 *  originalRichTextBox.Parent.BackColor = Color.Gray;
                 * }*/
            }
        }