C\#신분증 식별 관련 기술 기능 상세 설명

최근 에 C\#와 관련 된 OCR 기술 을 연 구 했 는데 이미지 인식 은 일반 C 와 C++와 같은 바 텀 언어 를 많이 만 들 었 다.C\#는 주로 포 장 된 구성 요 소 를 바탕 으로 호출 되 었 는데 여기 서 신분증 식별 방법 을 소개 한다.
환경 구축
다운로드 주소:EmguCV 홈 페이지

File 클래스 에서 이 EXE 를 다운로드 하여 설치 하고 설치 한 후 디 렉 터 리 에서 해당 구성 요 소 를 찾 을 수 있 으 며 응용 사례 도 있 습 니 다.
dll 폴 더 의 dll 은 C\#항목 에 인용 되 었 습 니 다.x64,x86,tessdata 는 OCR 인식 에 대응 하 는 라 이브 러 리 와 언어 라 이브 러 리 입 니 다.제 tessdata 에는 중국어 패 키 지 를 추가 하여 이 세 개의 폴 더 를 프로그램 실행 폴 더 에 넣 었 습 니 다.
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)
  {
   //               ,           
   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>
  ///     
  /// </summary>
  /// <param name="imageInput"></param>
  /// <returns></returns>
  private Image<Gray, Byte> randon(Image<Gray, Byte> imageInput)//                
  {
   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       
   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)
  {

  }
 }
}

이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기