3

我正在尝试做一些简单的 OCR 任务,但我仍在寻找免费的图书馆。既然每个人似乎都在使用 tesseract,有人可以给我一个简单但有效的例子,用 C# 或 VB.NET 使用 tesseractengine3.dll,好吗?在搜索了几个小时后,我找不到在 VS2010 和 .Net 4 下编译的任何文档或示例。

4

3 回答 3

1

尝试使用在http://vietocr.sourceforge.net/很棒的开源 OCR中使用的https://github.com/charlesw/tesseract库,并以简单的示例查看库源代码中的 BaseApiTester 项目。

于 2013-03-12T13:14:32.370 回答
1

尝试这个

    Ocr ocr = new Ocr();
    private void button1_Click(object sender, EventArgs e)
    {


         using (Bitmap bmp = new Bitmap(@"C:\OCR\ocr-test.jpg"))
        {
            tessnet2.Tesseract tessocr = new tessnet2.Tesseract();
            tessocr.Init(null, "eng", false);
            tessocr.GetThresholdedImage(bmp, Rectangle.Empty).Save("c:\\temp\\" + Guid.NewGuid().ToString() + ".bmp");
            // Tessdata directory must be in the directory than this exe
            Console.WriteLine("Multithread version");
            ocr.DoOCRMultiThred(bmp, "eng");
            Console.WriteLine("Normal version");
            ocr.DoOCRNormal(bmp, "eng");
        }
    }
   public class Ocr
    {
        public void DumpResult(List<tessnet2.Word> result)
        {
            foreach (tessnet2.Word word in result)
                Console.WriteLine("{0} : {1}", word.Confidence, word.Text);
        }

        public List<tessnet2.Word> DoOCRNormal(Bitmap image, string lang)
        {
            tessnet2.Tesseract ocr = new tessnet2.Tesseract();
            ocr.Init(null, lang, false);
            List<tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty);
            DumpResult(result);
            return result;
        }

        ManualResetEvent m_event;

        public void DoOCRMultiThred(Bitmap image, string lang)
        {
            tessnet2.Tesseract ocr = new tessnet2.Tesseract();
            ocr.Init(null, lang, false);
            // If the OcrDone delegate is not null then this'll be the multithreaded version
            ocr.OcrDone = new tessnet2.Tesseract.OcrDoneHandler(Finished);
            // For event to work, must use the multithreaded version
            ocr.ProgressEvent += new tessnet2.Tesseract.ProgressHandler(ocr_ProgressEvent);
            m_event = new ManualResetEvent(false);
            ocr.DoOCR(image, Rectangle.Empty);
            // Wait here it's finished
            m_event.WaitOne();
        }

        public void Finished(List<tessnet2.Word> result)
        {
            DumpResult(result);
            m_event.Set();
        }

        void ocr_ProgressEvent(int percent)
        {
            Console.WriteLine("{0}% progression", percent);
        }
    }
于 2013-03-12T11:52:54.730 回答
0

Tesseract 3.01 有一个 .NET 包装器:tesseract-ocr-dotnet

于 2012-07-30T23:53:38.663 回答