国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#身份證識別相關(guān)技術(shù)功能詳解

2020-01-24 00:34:35
字體:
供稿:網(wǎng)友

最近研究C#相關(guān)的OCR技術(shù),圖像識別一般C和C++這種底層語言做的比較多,C#主要是依托一些封裝好的組件進行調(diào)用,這里介紹一種身份證識別的方法。

環(huán)境搭建

下載地址:EmguCV官網(wǎng)

在File類別下下載這個EXE,進行安裝,安裝后在目錄下能找相應(yīng)組件,還有些應(yīng)用的案例。

dll文件夾中的dll引用到C#項目中,x64,x86,tessdata對應(yīng)OCR識別的類庫和語言庫,我tessdata中已添加中文語言包,將這三個文件夾放入程序執(zhí)行文件夾中。

Demo

自己做的小Demo如圖:身份證圖片是百度上下載的

不得不說這個類庫唯一弊端就是文字識別率太低,圖像識別效果也不太好

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using Emgu.CV;using Emgu.CV.OCR;using Emgu.CV.Structure;using System.IO;namespace EmguCV{ public partial class Form1 : Form {  Image<Gray, Byte> imageThreshold;  public Form1()  {   InitializeComponent();   pictureBox1.Enabled = false;  }  private void Form1_Load(object sender, EventArgs e)  {  }  private void button1_Click(object sender, EventArgs e)  {   //第一個參數(shù)是語言包文件夾的地址,不寫默認(rèn)在執(zhí)行文件夾下   Tesseract _ocr = new Tesseract(@"", "chi_sim", OcrEngineMode.TesseractOnly);   _ocr.SetImage(imageThreshold);   _ocr.Recognize();   String text = _ocr.GetUTF8Text();   this.textBox1.Text = text;  }  private void pictureBox2_Click(object sender, EventArgs e)  {   OpenFileDialog of = new OpenFileDialog();   of.Title = "請選擇圖片";   if (of.ShowDialog() == DialogResult.OK)   {    string file = of.FileName;    Image img = Image.FromFile(file);    pictureBox1.Image = img;   }   Bitmap bitmap = (Bitmap)this.pictureBox1.Image;   Image<Bgr, Byte> imageSource = new Image<Bgr, byte>(bitmap);   Image<Gray, Byte> imageGrayscale = imageSource.Convert<Gray, Byte>();   imageGrayscale = randon(imageGrayscale);   imageThreshold = imageGrayscale.ThresholdBinary(new Gray(100), new Gray(255));   this.pictureBox2.Image = imageThreshold.ToBitmap();  }  /// <summary>  /// 旋轉(zhuǎn)校正  /// </summary>  /// <param name="imageInput"></param>  /// <returns></returns>  private Image<Gray, Byte> randon(Image<Gray, Byte> imageInput)//圖像投影旋轉(zhuǎn)法傾斜校正子函數(shù)定義  {   int nwidth = imageInput.Width;   int nheight = imageInput.Height;   int sum;   int SumOfCha;   int SumOfChatemp = 0;   int[] sumhang = new int[nheight];   Image<Gray, Byte> resultImage = imageInput;   Image<Gray, Byte> ImrotaImage;   //20度范圍內(nèi)的調(diào)整   for (int ang = -20; ang < 20; ang = ang + 1)   {    ImrotaImage = imageInput.Rotate(ang, new Gray(1));    for (int i = 0; i < nheight; i++)    {     sum = 0;     for (int j = 0; j < nwidth; j++)     {      sum += ImrotaImage.Data[i, j, 0];     }     sumhang[i] = sum;    }    SumOfCha = 0;    for (int k = 0; k < nheight - 1; k++)    {     SumOfCha = SumOfCha + (Math.Abs(sumhang[k] - sumhang[k + 1]));    }    if (SumOfCha > SumOfChatemp)    {     resultImage = ImrotaImage;     SumOfChatemp = SumOfCha;    }   }   return resultImage;  }  private void pictureBox1_Click(object sender, EventArgs e)  {  } }}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 嘉义市| 越西县| 噶尔县| 石柱| 太原市| 云梦县| 东阿县| 宁安市| 赞皇县| 昌邑市| 凤山县| 固原市| 璧山县| 澄城县| 昆明市| 阿荣旗| 吉隆县| 滦平县| 黔江区| 苍梧县| 饶河县| 清徐县| 黑龙江省| 长乐市| 鄂托克前旗| 通州市| 从江县| 视频| 乌兰县| 惠安县| 安化县| 三门峡市| 秀山| 沐川县| 湘阴县| 安图县| 临汾市| 新邵县| 南丰县| 平南县| 汝阳县|