C#实现身份证识别功能的图文代码详解


当前第2页 返回上一页

不得不说这个类库唯一弊端就是文字识别率太低,图像识别效果也不太好

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

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)

  {

 

  }

 }

}

以上就是C#实现身份证识别功能的图文代码详解的详细内容!

返回前面的内容

相关阅读 >>

httpclient向https发送数据建立ssl连接时的异常

c#开发微信门户及应用(一)之微信接口的如何使用(图)

c# 定时器timer的实例介绍

c# 一些面试试题的实例教程

文件事物管理transactional file manager的实例详解

详细介绍.net中的性能改进

.net验证后台页面是否登录实例教程

分享一些平时收藏和应用的开源代码

c#与.net框架之间的关系是什么?c#程序的开发工具

c#中关于dictionary的用法详解

更多相关阅读请进入《csharp》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...