Tesseract 文本识别

Tesseract文本识别

安装

在项目中安装nugetTesseract

使用

在代码文件中进行引用using Tesseract;

去Github中下载语言包https://github.com/tesseract-ocr/tessdata 然后放到项目的bin\Debug\.netx

  1. 加载图片

    1
    
    Pix pix = Pix.LoadFromFile("C:\\1-r\\r\\r.png");
    
  2. 创建识别引擎,这里的tessdata要改成 bin\Debug\.netx下相应的文件夹名称,chi_sim根据语言进行更改

    1
    
    var tEngine = new TesseractEngine("tessdata", "chi_sim", EngineMode.Default);
    
  3. 识别

    1
    2
    3
    
    Page page = tEngine.Process(pix); //处理图像
    string str = page.GetText(); //获取字符串
    Console.WriteLine(str);	//输出
    
  4. 使用正则替换文本

    1
    
    Console.WriteLine(Regex.Replace(str, @"\s", ""));
    
使用 Hugo 构建
主题 StackJimmy 设计