示例:数字识别
要识别的图片:
halcon源码:
1: *读取图片
2: read_image(Image,'D:/MyFile/halcon/数字识别/')
3:?
4: *图像处理
5: decompose3(Image, ImageR, ImageG, ImageB)
6: threshold (ImageG, Regions, 0, 183)
7: connection (Regions, Connection)
8:?
9:select_shape (Connection, SelectedRegions, 'area', 'and', , 7500) 10:?
11: read_ocr_class_mlp('',OCRHandle)
12: do_ocr_multi_class_mlp(SelectedRegions,ImageG,OCRHandle, Class, Confidence)
halcon导出的C#代码:
1:pg*|BMP文件|*.bmp*|TIFF文件|*.tiff*";
30:?
31: = true;
32:?
33: = 1;
34:?
35:if () ==
36:?
37: {
38:?
39: ImagePath = ;
40:
41: , ImagePath);
42:
43: = true;
44:
45: }
46: }
47:?
48:private void btnRecognitionNumber_Click(object sender, EventArgs e)
49: {
50: ();
51: = 52:?
53: = false;
54: }
55: }
56:?
57://halcon导出的类
58:public partial class HDevelopExport
59: {
60:public HTuple hv_ExpDefaultWinHandle;
61:?
62: HObject ho_Image, ho_ImageR, ho_ImageG, ho_ImageB;
63: HObject ho_Regions, ho_Connection, ho_SelectedRegions; 64:?
65:?
66:// Local control variables
67: HTuple hv_OCRHandle, hv_Confidence;
68:public HTuple hv_Class;
69:?
70:public void InitHalcon()
71: {
72:// Default settings used in HDevelop
73: ("do_low_error", "false");
74: }
75:?
76:public void ReadImage(HTuple Window,string ImagePath) 77: {
78: hv_ExpDefaultWinHandle = Window;
79:?
80:// Initialize local and output iconic variables
81: (out ho_Image);
82:
83://读取图片
84: ();
85: (out ho_Image, ImagePath);
86: (ho_Image, hv_ExpDefaultWinHandle);
87: }
88:?
89:public void NumberRecognition()
90: {
91: (out ho_ImageR);
92: (out ho_ImageG);
93: (out ho_ImageB);
94: (out ho_Regions);
95: (out ho_Connection);
96: (out ho_SelectedRegions);
97://图像处理
98: ();
99: ();
100: ();
101: (ho_Image, out ho_ImageR, out ho_ImageG, out ho_ImageB 102: );
103: ();
104: (ho_ImageG, out ho_Regions, 0, 183);
105: ();
106: (ho_Regions, out ho_Connection);
107:?
108: ();
109: (ho_Connection, out ho_SelectedRegions, "area", "and",
110: , 7500);
111:?
112: ("", out hv_OCRHandle);
113: (ho_SelectedRegions, ho_ImageG, hv_OCRHandle,
114:out hv_Class, out hv_Confidence);
115:
116:?
117: ();
118: ();
119: ();
120: ();
121: ();
122: ();
123: ();
124:?
125: }
126:?
127: }
128: }
运行结果:
?