Exemple #1
0
        //识别内存中图像Base64编码后的数据,必须将导出到C/C++的函数设置为静态函数,并且为公有
        public static string OCRPictrueInMemory(string Base64Data)
        {
            Image image = Image2Bytes.BytesToImage(Convert.FromBase64String(Base64Data));

            try
            {
                using (var ocrEngine = new OneNoteOcrEngine())
                    if (!image.Equals(null))
                    {
                        var text = ocrEngine.Recognize(image);
                        if (text != null)
                        {
                            //Console.WriteLine("OcrRecognizeResult:\n");
                            return(text);
                        }
                    }
            }
            catch (OcrException ex)
            {
                Console.WriteLine("OcrException:\n" + ex);
            }
            catch (Exception ex)
            {
                Console.WriteLine("General Exception:\n" + ex);
            }
            return("Error");
        }
Exemple #2
0
        //识别本地磁盘中的图像,必须将导出到C/C++的函数设置为静态函数,并且为公有
        public static string OCRPictrueInDisk(string PicturePath)
        {
            Image image = Image.FromFile(PicturePath);

            try
            {
                using (var ocrEngine = new OneNoteOcrEngine())
                    if (!image.Equals(null))
                    {
                        var text = ocrEngine.Recognize(image);
                        if (text != null)
                        {
                            //Console.WriteLine("OcrException:\n");
                            return(text);
                        }
                    }
            }
            catch (OcrException ex)
            {
                Console.WriteLine("OcrException:\n" + ex);
            }
            catch (Exception ex)
            {
                Console.WriteLine("General Exception:\n" + ex);
            }

            return("Error");
        }