Tesseract文本识别
安装
在项目中安装nuget包 Tesseract
使用
在代码文件中进行引用using Tesseract;
去Github中下载语言包https://github.com/tesseract-ocr/tessdata 然后放到项目的bin\Debug\.netx下
-
加载图片
1Pix pix = Pix.LoadFromFile("C:\\1-r\\r\\r.png"); -
创建识别引擎,这里的
tessdata要改成bin\Debug\.netx下相应的文件夹名称,chi_sim根据语言进行更改1var tEngine = new TesseractEngine("tessdata", "chi_sim", EngineMode.Default); -
识别
1 2 3Page page = tEngine.Process(pix); //处理图像 string str = page.GetText(); //获取字符串 Console.WriteLine(str); //输出 -
使用正则替换文本
1Console.WriteLine(Regex.Replace(str, @"\s", ""));