/***********************************************************************************************************************
         *
         * Tesseract-OCR
         *
         ************************************************************************************************************************/
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <example>
        /// http://www.kanenote.org/blog/?p=1228
        /// https://qiita.com/nobi1234/items/c8d7b748c1aa31d771a1
        /// http://whoopsidaisies.hatenablog.com/entry/2013/12/16/174819
        /// https://tesseract-ocr.github.io/tessdoc/Data-Files.html
        /// https://kakusuke98.hatenablog.com/entry/2019/11/14/004609
        /// http://blog.qes.co.jp/2017/06/
        ///
        /// </example>
        private void btn_tesseract_ocr_Click(object sender, EventArgs e)
        {
            //言語ファイルの格納先
            //言語(日本語なら"jpn")
            //string langPath = @"C:\tessdata";
            string langPath = strFolderPath + @"\tessdata";
            string lngStr   = "eng";

            //画像ファイル
            //var img = new Bitmap(@"C:\Temp\test.jpg");
            Bitmap img = (Bitmap)picBoxDst.Image;


            // OCRの実行
            //OpenCvSharp.Text.OCRTesseract.Create("");
            using (var tesseract = new Tesseract.TesseractEngine(langPath, lngStr)) {
                Tesseract.Page page = tesseract.Process(img);       // OCRの実行

                //System.Console.Write(page.GetText());               //表示
                MessageBox.Show(page.GetText());


                //Console.WriteLine(page.GetText());
                //Console.ReadLine();
            }
        }
示例#2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int err_count = 0;

            while (err_count < 2)
            {
                Microsoft.VisualBasic.Interaction.AppActivate("Overwatch");
                SendKeys.SendWait("{PRTSC}");
                System.Diagnostics.Process[] processList = System.Diagnostics.Process.GetProcesses();
                if (System.Windows.Clipboard.ContainsImage())
                {
                    string lngStr   = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), @"tesseract-ocr\\");
                    string langPath = "eng";
                    var    img      = (Bitmap)System.Windows.Forms.Clipboard.GetImage();
                    var    bitmap24 = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                    using (var gr = Graphics.FromImage(bitmap24))
                    {
                        gr.DrawImage(img, new Rectangle(0, 0, bitmap24.Width, bitmap24.Height));
                    }

                    using (var tesseract = new Tesseract.TesseractEngine(lngStr, langPath))
                    {
                        tesseract.SetVariable("SEARCH", "1");
                        Tesseract.Page page = tesseract.Process(bitmap24);
                        if (page.GetText().Contains("SEARCH") || page.GetText().Contains("TIME") || page.GetText().Contains("ELAPSED") || page.GetText().Contains("LEAGUE") || page.GetText().Contains("HIGHLIGHTS") || page.GetText().Contains("SOCIAL") || page.GetText().Contains("EXIT"))
                        {
                            err_count = 0;
                        }
                        else
                        {
                            err_count += 1;
                        }
                    }
                }
                Thread.Sleep(50000);
            }

            DateTime dt     = DateTime.Now;
            string   result = dt.ToString("yyyy/MM/dd HH:mm:ss");
            string   lnk    = "https://maker.ifttt.com/trigger/match/with/key/xxxxxxxx/?value1=" + result;

            System.Diagnostics.Process.Start(lnk);

            Environment.Exit(0);
        }
示例#3
0
        public void doOcr()
        {
            Bitmap   resizer = new Bitmap(toOcr.Width * MULTI, toOcr.Height * MULTI);
            Graphics g       = Graphics.FromImage(resizer);

            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
            g.DrawImage(toOcr, 0, 0, resizer.Width, resizer.Height);
            Bitmap bw = Create1bppImage(resizer);

            Tesseract.Page p = tesseract.Process(bw);

            result = new OcrResults(p.GetText(), bw);

            //            bmp.Save("test0.jpg");
            //            resizer.Save("test.jpg");
            //            bw.Save("testBw.jpg");

            bw.Dispose();
            resizer.Dispose();
            g.Dispose();
            p.Dispose();
            toOcr.Dispose();
            return;
        }