环境vs 2019 .Net 4.8
新建一个wpf工程,拖放上一个button一个textbox
tesseract ocr  .Net  demo
nuget下载tesseract,版本信息如图所示
tesseract ocr  .Net  demo
MainWindow.xaml.cs文件代码如下:

using Microsoft.Win32;
using System.Windows;
using Tesseract;

namespace TestOCR
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == true)
            {
                var pix = Pix.LoadFromFile(ofd.FileName);
                var ocr = new TesseractEngine("./tessdata", "eng",EngineMode.TesseractAndCube);
                var page = ocr.Process(pix);
                textbox.Text = page.GetText();
                textbox.FontSize = 30;
            }
        }
    }
}

去下载tessdata训练文件:
https://github.com/tesseract-ocr/tesseract/wiki/Data-Files
tesseract ocr  .Net  demo
tesseract ocr  .Net  demo
下载后解压,然后一层层文件夹进去找到“tessdata”文件夹,把该文件夹放在wpf工程bin/debug目录里:
tesseract ocr  .Net  demo
然后准备一个带文字的图片,测试:
tesseract ocr  .Net  demo

相关文章:

  • 2021-11-12
  • 2022-12-23
  • 2021-11-13
  • 2021-11-30
  • 2021-11-30
  • 2021-10-31
  • 2021-08-21
猜你喜欢
  • 2021-12-10
  • 2022-02-20
  • 2021-06-08
  • 2022-12-23
相关资源
相似解决方案