ocr識別開源軟件tesseract試用記錄

針對公司系統現場查驗場景中,須要用到拍照識別並查驗證件信息的需求。對其中關鍵的ocr開源軟件tesseract技術進行了簡單試用記錄。git

一、新建一個winform測試項目,經過nuget搜索安裝tesseract的sdk。github

二、去github下載語言包:https://github.com/tesseract-ocr/tessdata,分各類語言,下載英文(eng.traineddata)以及中文(chi_sim.traineddata)的,下載完成後放到測試項目的\debug\tessdata目錄下,注意只能是tessdata目錄,名字不能錯。測試

三、代碼以下:this

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tesseract;spa

namespace TestOCR
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}debug

/// <summary>
/// 加載圖片顯示到picturebox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK && (openFileDialog1.FileName != ""))
{
pictureBox1.ImageLocation = openFileDialog1.FileName;
}
}3d

/// <summary>
/// 調用tesseract對所選圖片文字進行識別
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
using (TesseractEngine te = new TesseractEngine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tessdata"), "chi_sim+eng", EngineMode.Default))
{
using (var pix = PixConverter.ToPix(new Bitmap(pictureBox1.ImageLocation)))
{
var page = te.Process(pix);
string text = page.GetText();
this.textBox1.Text = text;
}
}
}
}
}orm

  a、運行,選擇一個字少的,識別結果以下,能夠發現清晰的字大的地方,識別率還能夠,可是最下面一行就徹底變亂碼了:blog

 

 

  b、換一張圖,從業資格證,格式比較複雜的,圖片清晰度已經很能夠了,可是識別結果基本不可用。token

 

  

四、由於手上其餘要跟的事情太多,沒有再進一步研究,基本結論以下:

  a、這個東西要想達到實用的效果,還有不少事情要作,遠不是寫個demo那麼簡單。

  b、咱們的場景過程:現場手機拍證件或者拍車牌—>上傳拍攝圖片,調用ocr服務識別—>針對識別出的特徵信息(證件號或者車牌號),調用對應的查驗接口—>返回相關信息。

  c、分析:現場拍攝的圖片質量,會比測試使用圖片質量差不少(主要是清晰度、角度)。所以,實際咱們在識別以前,還須要對圖片進行不少的預處理來提升識別率,例如對圖片進行形狀校訂、對圖片進行去噪點、包括針對特定證件的特定位置進行識別排除干擾項、對識別語言包進行鍼對性的訓練等工做,有大量的工做要作。目前決定暫時再也不推動研究工做。建議直接使用市場中成熟大廠的產品。

相關文章
相關標籤/搜索