Exemple #1
0
 public static LogTools GetInstance()
 {
     if (instance == null)
     {
         instance = new LogTools();
     }
     return(instance);
 }
Exemple #2
0
        public string OCRWithTesseract(Mat mat, string lans)
        {
            var configMgr          = ConfigMgr.GetInstance();
            var randStr            = DateTime.Now.ToString("yyMMddHHmmssffff") + mat.GetHashCode().ToString();
            var tempImgStorePath   = configMgr.GetCacheFileFullPath($"tesseract_{randStr}.png");
            var resName            = $"tesseract_result_{randStr}";
            var tempResPathForTess = configMgr.GetCacheFileFullPath($"{resName}");
            var tempResStorePath   = configMgr.GetCacheFileFullPath($"{resName}.txt");

            mat.SaveImage(tempImgStorePath);
            var tesseratPath = ConfigMgr.GetInstance().TesseractPath;
            var startInfo    = new ProcessStartInfo()
            {
                FileName    = tesseratPath,
                Arguments   = string.Format("{0} {1} -l {2} --psm 6", tempImgStorePath, tempResPathForTess, lans),
                WindowStyle = ProcessWindowStyle.Hidden,
                //RedirectStandardOutput = true,
                //RedirectStandardError = true,
                //UseShellExecute = false,
            };
            var s = "";

            try
            {
                var proc = Process.Start(startInfo);
                proc.WaitForExit();
                //var output = proc.StandardOutput.ReadToEnd();
                //var error = proc.StandardError.ReadToEnd();
                s = File.ReadAllText(tempResStorePath);
                s = FilterTesseractResult(s);
                LogTools.GetInstance().Info("OCR:" + s);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                File.Delete(tempImgStorePath);
                File.Delete(tempResStorePath);
            }
            return(s);
        }
Exemple #3
0
 private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
 {
     LogTools.GetInstance().Error(e.Exception.Message);
 }