Ejemplo n.º 1
0
    public void CapturePhoto()
    {
        Texture2D     screenShot;
        RenderTexture rt = new RenderTexture(width, height, 1);

        cameras.targetTexture = rt;
        cameras.Render();
        RenderTexture.active = rt;
        screenShot           = new Texture2D(width, height, TextureFormat.RGB24, false);
        screenShot.ReadPixels(new Rect(0, 0, width, height), 0, 0);
        screenShot.Apply();

        //在Asset路径下新建一个StreamingAsset文件夹
        fileName = Application.streamingAssetsPath + "/capture.jpg";
        //byte[] bytes = screenShot.EncodeToJPG();

        ScaleTextureCutOut(screenShot, 0, 0, 1024, 768);
        Debug.Log(string.Format("截屏一张照片: {0}", fileName));
        var image = File.ReadAllBytes(fileName);

        var client = new Ocr(api_key, secret_key);

        //client = new Body(api_key, secret_key);
        client.Timeout = 60000;  // 修超时时间

        var result = client.GeneralBasic(image);

        resultMsg.text = result.ToString();
        Debug.Log(resultMsg.text);
        Thread.Sleep(5000);
    }
Ejemplo n.º 2
0
        public static string BaiduAPI(Image bitmap)
        {
            string token      = "24.5142d6d4850be2c098165f677b8fe68b.2592000.1603087490.282335-22701901";
            string OCRresult  = "";
            string API_KEY    = "p8Tgf4cVCWi0QOGjnqfu22G9";
            string SECRET_KEY = "UvzNMtiR728kmjai8UjMLEctfZ2eVPNm";
            var    client     = new Ocr(API_KEY, SECRET_KEY);

            client.Timeout = 6000;  // 修改超时时间
            MemoryStream ms = new MemoryStream();

            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            byte[] image = ms.GetBuffer();
            ms.Close();
            try
            {
                var result = client.GeneralBasic(image);
                for (int i = 0; i < result["words_result"].Count(); i++)
                {
                    OCRresult = OCRresult + result["words_result"][i]["words"].ToString() + "\r\n";
                }
            }
            catch (OverflowException)
            {
                OCRresult = "网络出错请重试";
            }
            return(OCRresult);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <CaptureResult> > Get()
        {
            _logger.LogInformation("Client requested capture");
            try
            {
                // Capture from the card
                Capture      capture = new Capture(_logFactory);
                MemoryStream stream  = new MemoryStream();
                await capture.CapturePhoto(stream);

                stream.Position = 0;

                // For debugging
                //using FileStream stream = System.IO.File.OpenRead(@"procimages/618f82be-b899-47dd-a7a7-966484772220_original.png");

                // OCR and return
                using Ocr ocr = new Ocr(stream, _logFactory);
                ocr.Process();
                return(Ok(ocr.Result));
            }
            catch (Exception e)
            {
                _logger.LogError("Exception during capture", e);
                return(BadRequest(new { message = e.Message + "\n" + e.StackTrace }));
            }
        }
Ejemplo n.º 4
0
            public void OCR_PDF_Extract(string PDFType)

            {
                //string PDFLoation = ScenarioContext.Current["PDFpath"].ToString();
                string PDFLoation  = "C:\\demo";
                string newfilename = getLatestfilename(PDFLoation);

                //string sValue = null;
                if (newfilename.Contains("_"))
                {
                    string TrimNewfile  = newfilename.Substring(newfilename.LastIndexOf('_') + 1).ToString();
                    var    directory    = new DirectoryInfo(PDFLoation);
                    string concatSource = PDFLoation + "\\" + TrimNewfile;
                    string concatDes    = PDFLoation + "\\" + PDFType + "_" + TrimNewfile;
                    Thread.Sleep(3000);
                    //File.Move(concatSource, concatDes);
                    //string dataloc = PDFLoation + PDFType + "__Page -{0}.{1}";
                    string adda    = "\\SPLIT";
                    string dataloc = PDFLoation + adda + "__Page -{0}.{1}";
                    Ocr.ConvertorFromPdFtoData(concatDes, dataloc);
                    //return dataloc;
                }
                else
                {
                    string concatSource = PDFLoation + "\\" + newfilename;
                    string concatDes    = PDFLoation + "\\" + PDFType + "_" + newfilename;
                    Thread.Sleep(3000);
                    //File.Move(concatSource, concatDes);
                    string dataloc = PDFLoation + "\\" + PDFType + "__Page -{0}.{1}";
                    Ocr.ConvertorFromPdFtoData(concatDes, dataloc);
                    //return dataloc;
                }
            }
Ejemplo n.º 5
0
        public ActionResult Upload(HttpPostedFileBase book)
        {
            HttpPostedFileBase bookImage = null;

            if (Request.Files.Count == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
            else
            {
                bookImage = Request.Files[0];
            }
            if (bookImage != null && (bookImage.ContentType == "image/jpeg" || bookImage.ContentType == "image/jpg" || bookImage.ContentType == "image/png"))
            {
                string fileName            = bookImage.FileName;
                System.Drawing.Image image = System.Drawing.Image.FromStream(bookImage.InputStream);
                Bitmap bmp    = new Bitmap(image);
                string result = Ocr.Doit(bmp).Trim();
                if (result == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
                }

                return(Json(new { isbn = result }, JsonRequestBehavior.AllowGet));
            }
            return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
        }
Ejemplo n.º 6
0
        protected override void Execute(CodeActivityContext context)
        {
            string path       = FileName.Get(context);
            string API_KEY    = APIKey.Get(context);
            string SECRET_KEY = SecretKey.Get(context);

            img = image.Get(context);
            try
            {
                if (path != null)
                {
                    by = SaveImage(path);
                }
                else
                {
                    by = ConvertImageToByte(img);
                }
                var client = new Ocr(API_KEY, SECRET_KEY);
                //修改超时时间
                client.Timeout = 60000;
                //参数设置
                var options = new Dictionary <string, object>
                {
                    { "detect_direction", detect_direction.ToString().ToLower() },
                    { "detect_language", detect_language.ToString().ToLower() }
                };
                //带参数调用网络图片文字识别
                string result = client.WebImage(by, options).ToString();
                Result.Set(context, result);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", e.Message);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 通用文字识别
        /// </summary>
        /// <param name="byteArr_Image"></param>
        /// <returns></returns>
        public static OCRResult Excute_GeneralBasic(byte[] byteArr_Image)
        {
            OCRResult r = null;

            try
            {
                var options = new Dictionary <string, object>
                {
                    { "language_type", "CHN_ENG" },  //
                    { "detect_direction", "false" }, // 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:
                    { "detect_language", "true" },   // 是否检测语言,默认不检测。当前支持(中文、英语、日语、韩语)
                    { "probability", "false" } // 是否返回识别结果中每一行的置信度
                };

                Ocr client = new Ocr(ApiKey, SecretKey);
                Newtonsoft.Json.Linq.JObject ocrResult = client.GeneralBasic(image: byteArr_Image, options: options);
                r = getOCRResult(ocrResult);
            }
            catch (Exception ex)
            {
                r               = new OCRResult();
                r.IsComplete    = false;
                r.ExceptionInfo = ex.GetFullInfo();
                r.IsSuccess     = false;
            }

            return(r);
        }
Ejemplo n.º 8
0
        private PreProcessor Configure(Ocr ocr)
        {
            ocr.License            = license;
            ocr.TempFolder         = Path.Combine(tempPath, Guid.NewGuid().ToString());
            ocr.Language           = SupportedLanguages.English;
            ocr.EnableDebugOutput  = true;
            ocr.GetAdvancedOCRData = true;
            ocr.LogToFile          = true;
            //ocr.HandleExceptionsInternally = false;

            PreProcessor preProcessor = new PreProcessor();

            preProcessor.Deskew            = true;
            preProcessor.Autorotate        = false;
            preProcessor.KeepOriginalImage = true;

            //Create new binarization object
            Binarization binarize = new Binarization();

            //Enable binarization
            binarize.Binarize = true;

            //Assign it to PreProcessor
            preProcessor.Binarization = binarize;

            return(preProcessor);
            //ocr.Recognize(preProcessor);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 通用文字识别(含位置信息版)
        /// </summary>
        /// <param name="byteArr_Image"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static OCRResult Excute_General(byte[] byteArr_Image)
        {
            OCRResult r = null;

            try
            {
                var options = new Dictionary <string, object>
                {
                    { "recognize_granularity", "big" }, // 是否定位单字符位置,big:不定位单字符位置,默认值;small:定位单字符位置
                    { "language_type", "CHN_ENG" },     // 识别语言类型,默认为CHN_ENG。可选值包括:
                    { "detect_direction", "false" },    // 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:
                    { "detect_language", "false" },     // 是否检测语言,默认不检测。当前支持(中文、英语、日语、韩语)
                    { "vertexes_location", "false" },   // 是否返回文字外接多边形顶点位置,不支持单字位置。默认为false
                    { "probability", "false" } // 是否返回识别结果中每一行的置信度
                };

                Ocr client = new Ocr(ApiKey, SecretKey);
                Newtonsoft.Json.Linq.JObject ocrResult = client.General(image: byteArr_Image, options: options);
                r = getOCRResult(ocrResult);
            }
            catch (Exception ex)
            {
                r               = new OCRResult();
                r.IsComplete    = false;
                r.ExceptionInfo = ex.GetFullInfo();
                r.IsSuccess     = false;
            }

            return(r);
        }
        protected override void Execute(CodeActivityContext context)
        {
            string path       = FileName.Get(context);
            string API_KEY    = APIKey.Get(context);
            string SECRET_KEY = SecretKey.Get(context);

            img = image.Get(context);
            try
            {
                if (path != null)
                {
                    by = SaveImage(path);
                }
                else
                {
                    by = ConvertImageToByte(img);
                }
                var client = new Ocr(API_KEY, SECRET_KEY);
                //修改超时时间
                client.Timeout = 60000;
                //参数设置
                var options = new Dictionary <string, object>
                {
                    { "detect_direction", detect_direction.ToString().ToLower() },
                    { "probability", probability.ToString().ToLower() }
                };
                //带参数调用通用文字识别(高精度版)
                string result = client.AccurateBasic(by, options).ToString();
                Result.Set(context, result);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, Localize.LocalizedResources.GetString("msgErrorOccurred"), e.Message);
            }
        }
Ejemplo n.º 11
0
        public ActionResult Upload(HttpPostedFileBase book)
        {
            HttpPostedFileBase bookImage = null;

            if (Request.Files.Count == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
            else
            {
                bookImage = Request.Files[0];
            }
            if (bookImage != null && (bookImage.ContentType == "image/jpeg" || bookImage.ContentType == "image/jpg" || bookImage.ContentType == "image/png"))
            {
                string fileName            = bookImage.FileName;
                System.Drawing.Image image = System.Drawing.Image.FromStream(bookImage.InputStream);
                Bitmap bmp    = new Bitmap(image);
                string result = Ocr.Doit(bmp).Trim();
                if (result == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
                }
                string[] words = result.Split(' ');

                List <string> wordList = words.ToList();
                string        isbn     = wordList[wordList.Count - 1];
                wordList.RemoveAt(wordList.Count() - 1);
                string name = string.Join(" ", wordList.ToArray());

                return(Json(new { name = name, isbn = isbn }, JsonRequestBehavior.AllowGet));
            }
            return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
        }
Ejemplo n.º 12
0
        public void Snap(int x, int y, int width, int height)
        {
            //把图片赋值给 pb_Capture
            pb_Capture.BackgroundImageLayout = ImageLayout.Zoom;
            CaptureImg = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(CaptureImg);

            g.CopyFromScreen(x, y, 0, 0, new System.Drawing.Size(width, height));
            if (width < pb_Capture.Width && height < pb_Capture.Height)
            {
                pb_Capture.BackgroundImageLayout = ImageLayout.Center;
            }
            pb_Capture.BackgroundImage = CaptureImg;

            // 保存文件到本地
            System.Drawing.Imaging.Encoder eQuality = System.Drawing.Imaging.Encoder.Quality;
            EncoderParameter  epQuality             = new EncoderParameter(eQuality, 100L);
            EncoderParameters epQuality_s           = new EncoderParameters();

            epQuality_s.Param[0] = epQuality;
            if (!Directory.Exists(CapturePath))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(CapturePath);
                directoryInfo.Create();
            }
            String filename = System.Guid.NewGuid().ToString();

            CaptureImg.Save(CapturePath + filename + ".jpg", GetEncoderInfo("image/jpeg"), epQuality_s);

            // 识别图片
            String API_KEY    = ini.ReadIniData("apikey", "value", "", IniPath);
            String SECRET_KEY = ini.ReadIniData("secretkey", "value", "", IniPath);
            Ocr    client     = new Ocr(API_KEY, SECRET_KEY);

            client.Timeout = 60000;  // 修改超时时间
            byte[]  image          = File.ReadAllBytes(CapturePath + filename + ".jpg");
            JObject textJsonObject = client.GeneralBasic(image);

            // 组装text
            String text = "";

            if (textJsonObject["words_result"] != null)
            {
                JArray ja = JArray.Parse(textJsonObject["words_result"].ToString());
                foreach (JObject jo in ja)
                {
                    text = text + jo["words"].ToString() + "\n";
                }
            }
            else
            {
                text = "【识别错误】" + "\n"
                       + "错误信息为" + "\n"
                       + textJsonObject.ToString();
            }
            rtb_Text.Text = text;
            //复制给粘贴板
            Clipboard.SetDataObject(text);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Resets the properties to their default value.
 /// </summary>
 public void Reset()
 {
     General.Reset();
     Proxies.Reset();
     Captchas.Reset();
     Selenium.Reset();
     Ocr.Reset();
 }
 public void executarEvento(object sender, FileSystemEventArgs e)
 {
     while (Ocr.IsFileLocked(e.FullPath))
     {
     }
     File.AppendAllText("logprocessado.txt", e.FullPath);
     executar(e.FullPath);
 }
Ejemplo n.º 15
0
 private void Btnstartocr_Click(object sender, EventArgs e)
 {
     apikey    = textBox1.Text;
     secretkey = textBox2.Text;
     client    = new Baidu.Aip.Ocr.Ocr(apikey, secretkey);
     this.t1   = new Thread(new ThreadStart(NewMethod));
     this.t1.Start();
 }
Ejemplo n.º 16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string APP_ID     = "14701082";
            string API_KEY    = "4Eedc93qsNT084m5Twh3TxPk";
            string SECRET_KEY = "P8Mnu7LVwvzG1YG6PwpWNGCYQHjLYjRb";

            client         = new Ocr(API_KEY, SECRET_KEY);
            client.Timeout = 60000;  // 修改超时时间
        }
Ejemplo n.º 17
0
        private void InltializeRecognition()
        {
            var APP_ID     = "11495528";
            var API_KEY    = "KLujEE43w3cwnGxjOGZ74o58";
            var SECRET_KEY = "9PzWnq5BOh8ipbdf7WdVp50Ax4f5S33B";

            m_client         = new Baidu.Aip.Ocr.Ocr(API_KEY, SECRET_KEY);
            m_client.Timeout = 60000;
        }
Ejemplo n.º 18
0
 private string readPdf(string filename)
 {
     loadingForm.setProgress("Reading " + SafeFileName);
     using (var Input = new OcrInput(filename))
     {
         var Result = Ocr.Read(Input);
         return(Result.Text);
     }
 }
Ejemplo n.º 19
0
        public static string Cpzcz()
        {
            var client = new Ocr(API_KEY, SECRET_KEY);
            var image  = File.ReadAllBytes("D:\\Code\\Android\\MsWeb\\MsWeb\\images\\ocr\\text1.jpg");
            // 通用文字识别
            // 过程中发生的网络失败等系统错误,将会抛出相关异常,请使用 try/catch 捕获。
            var result = client.GeneralBasic(image, null);

            return(result.ToString());
        }
Ejemplo n.º 20
0
    // Use this for initialization
    void Start()
    {
        api_key    = "QusDMkImWclCNsweUR7KXjvm";
        secret_key = "vFxAWvY7yjDc7GcYCDQFL2p3B00Tofja";
        StartCoroutine(CallCamera());
        var client = new Ocr(api_key, secret_key);

        //client = new Body(api_key, secret_key);
        client.Timeout = 60000;
    }
 private Ocr getOcr()
 {
     if (mOcr == null)
     {
         string apiKey   = ConfigurationHelper.GetConfig(ConfigItemName.baiduApiKey.ToString());
         string apiScret = ConfigurationHelper.GetConfig(ConfigItemName.baiduApiSecretKey.ToString());
         mOcr = new Ocr(apiKey, apiScret);
     }
     return(mOcr);
 }
        /// <summary>
        /// Automatic Recognition 开始自动识别
        /// </summary>
        private void AutomaticRecognition()
        {
            string apiKey   = ConfigurationHelper.GetConfig(ConfigItemName.baiduApiKey.ToString());
            string apiScret = ConfigurationHelper.GetConfig(ConfigItemName.baiduApiSecretKey.ToString());
            Ocr    ocr      = new Ocr(apiKey, apiScret);

            Newtonsoft.Json.Linq.JObject ob           = ocr.BusinessLicense(FileHelper.GetBytes(imagePath));
            BaiduLicenseRecognition      baiduLicense = BaiduAipHelper.getLicenseRecognition(ob);

            bindingControlValue(baiduLicense);
        }
        /// <summary>
        /// Automatic Recognition 开始自动识别
        /// </summary>
        private void IDRecognition()
        {
            string apiKey   = ConfigurationHelper.GetConfig(ConfigItemName.baiduApiKey.ToString());
            string apiScret = ConfigurationHelper.GetConfig(ConfigItemName.baiduApiSecretKey.ToString());
            Ocr    ocr      = new Ocr(apiKey, apiScret);

            Newtonsoft.Json.Linq.JObject ob = ocr.Idcard(FileHelper.GetBytes(imagePath), "front");
            //BaiduLicenseRecognition baiduLicense = BaiduAipHelper.getLicenseRecognition(ob);
            ConsoleHelper.writeLine(ob.ToString());
            MessageBox.Show(ob.ToString());
        }
Ejemplo n.º 24
0
        public Form3()
        {
            InitializeComponent();

            string APP_ID     = "15147577";
            string API_KEY    = "XG2oDGFRG6VWCzLXta0qKxEI";
            string SECRET_KEY = "E48m5rAKTLlD4ZmE9mGBqIwXi7OiEbZQ ";

            client         = new Ocr(API_KEY, SECRET_KEY);
            client.Timeout = 60000;  // 修改超时时间
        }
Ejemplo n.º 25
0
        public void ReadImageToPix()
        {
            Mock <IReadPicture> mock = new Mock <IReadPicture>();

            mock.Setup(m => m.ReadImageFromFile("Test"))
            .Returns(Pix.Create(200, 200, 32));

            Ocr ocr  = new Ocr(mock.Object);
            var test = ocr.ReadFile("Test");

            Assert.True(test);
        }
Ejemplo n.º 26
0
 /// <summary>
 /// 调用通用文字识别
 /// </summary>
 /// <param name="FileName"></param>
 /// <returns>OCRResult</returns>
 public static string GeneralOCRBasic(Func <Ocr, JObject> func)
 {
     try
     {
         var ocr = new Ocr(AppKey, AppSecret);
         return(JsonConvert.SerializeObject(func(ocr)));
     }
     catch (Exception ex)
     {
         Log.Error("图片ORC错误", ex);
         throw new Exception(ex.Message);
     }
 }
Ejemplo n.º 27
0
        private T ScanCatchOcrFailedExeption <T>(Ocr <T> ocr, Bitmap bitmap, Rectangle r)
        {
            try
            {
                var result = ocr.Process(bitmap, r);

                return(result);
            }
            catch (OcrFailedException)
            {
                return(default(T));
            }
        }
Ejemplo n.º 28
0
        private void pictureBoxCut_MouseUp(object sender, MouseEventArgs e)
        {
            if (IsOcrMaking)
            {
                return;
            }
            IsOcrMaking = true;

            OcrRectangle = CalcOcrRectangle();

            StartPoint = Point.Empty;
            Task.Run(() =>
            {
                var timer = new System.Threading.Timer(new TimerCallback((state =>
                {
                    this.BeginInvoke(new Action(() => this.Refresh()));
                })), null, 300, 300);
                try
                {
                    IsOcrMaking = true;

                    if (OcrRectangle == null)
                    {
                        return;
                    }

                    //鼠标相对于窗体左上角的坐标
                    ocrStopwatch.Restart();
                    using (var bitBmp = this.Image.Clone(OcrRectangle.Value, this.Image.PixelFormat))
                    {
                        var Result = Ocr.Read(bitBmp);

                        ocrStopwatch.Stop();

                        this.BeginInvoke(new Action(() => this.Refresh()));

                        OcrString = Result.Text;
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
                finally
                {
                    timer.Dispose();
                    timer       = null;
                    IsOcrMaking = false;
                }
            });
        }
Ejemplo n.º 29
0
        private JObject ExtractTextFromImage(string filePath)
        {
            var client  = new Ocr(API_KEY, SECRET_KEY);
            var image   = File.ReadAllBytes(filePath);
            var options = new Dictionary <string, object> {
                { "language_type", "CHN_ENG" },
                { "detect_direction", "false" },
                { "detect_language", "true" },
                { "probability", "false" }
            };
            JObject TextObjet = client.GeneralBasic(image, options);

            return(TextObjet);
        }
Ejemplo n.º 30
0
 public JObject GeneralBasic(Image image)
 {
     try
     {
         var client = new Ocr(ModelFactory.API_KEY, ModelFactory.SECRET_KEY);
         var result = client.GeneralBasic(FileOperate.ImageToBytes(image));
         Console.WriteLine(result);
         return(result);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
        internal static unsafe int IsBitmapsAlike(NikseBitmap bmp1, Ocr.Binary.BinaryOcrBitmap bmp2)
        {
            int different = 0;
            int maxDiff = bmp1.Width * bmp1.Height / 5;

            for (int x = 1; x < bmp1.Width; x++)
            {
                for (int y = 1; y < bmp1.Height; y++)
                {
                    if (bmp1.GetAlpha(x, y) < 100 && bmp2.GetPixel(x, y) > 0)
                        different++;
                }
                if (different > maxDiff)
                    return different + 10;
            }
            return different;
        }
Ejemplo n.º 32
0
        private string processImage(string imageInput, string outputFilePath)
        {
            var debugMessage = new StringBuilder();
            try
            {
                debugMessage.Append("Process Image output file path " + outputFilePath);
                var ocr = new Ocr();
                var preProcessor = new PreProcessor();

                debugMessage.Append("Objects created");

                preProcessor.Deskew = true;
                preProcessor.Autorotate = false;
                preProcessor.RemoveLines = true;
                preProcessor.Binarize = 96;
                preProcessor.Morph = "c2.2";

                ocr.License =
               "MD1BZHZhbmNlZDsxPWtlZXJ0aSAtIGt2a2lydGh5QGdtYWlsLmNvbTsyPTUyNDY4Njg5OTE5MTMwMjg5NTI7Mz1rZWVydGkgLSBrdmtpcnRoeUBnbWFpbC5jb207ND05OTk7NT1UcnVlOzUuMT1GYWxzZTs3PTYzNTE4ODYwODAwMDAwMDAwMDs4PTQxRDA3NEFFODJFQjI3QjM3RDdGMTUzQ0REQjVEQkNFNEVGRjdGREU5MEIwOTg1MjkwQ0JDREFCQTM3MEFBNzU7OT0xLjQxLjAuMA";
                
                ocr.ResourceFolder = @"C:\Aquaforest\OCRSDK\bin";
                ocr.EnableConsoleOutput = true;
                ocr.EnableTextOutput = true;

                //ocr.ReadBMPSource(@"C:\Users\KotaruV\Documents\Visual Studio 2012\Projects\Playground\OCRConsoleApp\OCRConsoleApp\images\3.jpg");
                //ocr.ReadTIFFSource(imageInput);
                ocr.ReadBMPSource(imageInput);

                debugMessage.Append("Read from bmp source. ");
                ocr.Recognize(preProcessor);
                debugMessage.Append("Recognize executed. ");
                
                ocr.SaveTextOutput(outputFilePath, true);
                var ocrText = getOcrTextFromFile(outputFilePath);
                debugMessage.Append("Saved text output. ");
                ocr.DeleteTemporaryFiles();
                debugMessage.Append("Deleted temporary files. ");
                return ocrText;
            }
            finally
            {
                System.Diagnostics.EventLog.WriteEntry("Application", debugMessage.ToString(), System.Diagnostics.EventLogEntryType.Error);
            }

        }
Ejemplo n.º 33
0
 private static void InitTesseract64()
 {
     pOcr = new Ocr64();
     pTesseract = new tessnet2_64::tessnet2.Tesseract();
     ((tessnet2_64::tessnet2.Tesseract)pTesseract).Init(null, "eng", false);
 }
        internal static int IsBitmapsAlike(Ocr.Binary.BinaryOcrBitmap bmp1, NikseBitmap bmp2)
        {
            int different = 0;
            int maxDiff = bmp1.Width * bmp1.Height / 5;

            for (int x = 0; x < bmp1.Width; x++)
            {
                for (int y = 0; y < bmp1.Height; y++)
                {
                    //if (!IsColorClose(bmp1.GetPixel(x, y), bmp2.GetPixel(x, y), 20))
                    if (bmp1.GetPixel(x, y) > 0 && bmp2.GetAlpha(x, y) < 100)
                        different++;
                }
                if (different > maxDiff)
                    return different + 10;
            }
            return different;
        }