This article mainly introduces the C # ID card identification Related technical details, with a certain reference value, interested in small partners can refer to
Recent study of C # related OCR technology, image recognition generally C and C + + This low-level language to do more, C # mainly relies on some packaged components to make calls, here is a method of identity card recognition.
Environment construction
Download Address: EMGUCV official website
Download this exe under the file category, install it, find the corresponding component in the directory after installation, and some application cases.
DLL is referenced in a C # project, X64,x86,tessdata corresponds to a class library and a language library for OCR recognition, and I have added the Chinese language pack in Tessdata to put these three folders into the Program execution folder.
Demo
I do the small demo ID image is Baidu downloaded
Have to say that the only drawback of this class library is that the text recognition rate is too low, the image recognition effect is not very good
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) { The first parameter is the address of the language pack folder, not written by default under the execution folder 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 = "Please select Picture"; 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, new Gray (255)); This.pictureBox2.Image = Imagethreshold.tobitmap (); }///<summary>//rotation correction///</summary>/<param name= "Imageinput" ></param>//<returns ></returns> private Image<gray, byte> Randon (Image<gray, byte> imageinput)//Image projection Rotation method Tilt Correction sub function definition {in T 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; Adjustment within 20 degrees for (int ang = -20; ang <; 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) {}}}