public decimal GetOcrMoney(ScreenConfig config, out Bitmap bitMap) { bitMap = ScreenPlugins.GetBitmapFromPoint(config); if (bitMap == null) { return(0M); } #region 图片处理 方便OCR解析更加准确 var bitMapOce = bitMap; bitMapOce = GetZoom(bitMap, 3.5); //灰度化 ToGrey(bitMapOce); //二值化 Thresholding(bitMapOce); #endregion #region OCR文字识别 var ocr = new TesseractEngine(_config.OCRResourcePath, "chi_sim", EngineMode.Default); var page = ocr.Process(bitMapOce, PageSegMode.RawLine); #endregion #region OCR解析处理 var moneyStr = page?.GetText(); foreach (var item in ConstDefintion.MONEY_REPLACE) { moneyStr = moneyStr.Replace(item.Key, item.Value); } #endregion TextHelper.Write("data->" + page?.GetText() + " 转换后->" + moneyStr); return(ResolveMoney(moneyStr)); }
/// <summary> /// 重新加载配置 /// </summary> /// <param name="config"></param> public void InitConifg(ScreenConfig config) { if (string.IsNullOrEmpty(config?.OCRResourcePath)) { config.OCRResourcePath = _config.OCRResourcePath; } _config = config; }
public ScreenTimerPlugins(ScreenConfig config) { if (config == null) { config = new ScreenConfig(); } config.OCRResourcePath = config?.OCRResourcePath ?? AppDomain.CurrentDomain.BaseDirectory + "resource\\tessdata"; if (string.IsNullOrEmpty(config?.OCRResourcePath)) { throw new ArgumentNullException("OCR 语言库资源地址未配置"); } _config = config; }