-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_operation.hdev
170 lines (170 loc) · 8.34 KB
/
basic_operation.hdev
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.2" halcon_version="19.11.0.0">
<procedure name="main">
<interface/>
<body>
<c></c>
<c>* 提取ROI区域</c>
<l>dev_clear_window()</l>
<l>read_image (Image, 'claudia')</l>
<l>dev_open_window(0, 0, 512, 512, 'black', WindowHandle)</l>
<l>dev_display(Image)</l>
<c></c>
<l>draw_rectangle1(WindowHandle, Row1, Column1, Row2, Column2)</l>
<c></c>
<l>gen_rectangle1(Rectangle,Row1, Column1, Row2, Column2)</l>
<l>reduce_domain(Image, Rectangle, ImageReduced)</l>
<c></c>
<l>stop ()</l>
<c></c>
<c>* 识别条形码的示例</c>
<l>dev_update_off ()</l>
<l>dev_set_color (['#ff000080','#00ff0080','#ff00ff80','#00ffff80','#ffff0080','#0000ff80'])</l>
<l>dev_set_line_width (3)</l>
<c as_id="image_acquisition" as_name="Image Acquisition 01" as_grp="[1,1]" as_ord="1">* Image Acquisition 01: Code generated by Image Acquisition 01</c>
<l as_id="image_acquisition" as_name="Image Acquisition 01" as_grp="[2,1]" as_ord="1">read_image (Image, 'barcode/ean13/ean1305.png')</l>
<l>create_bar_code_model ([], [], BarCodeHandle)</l>
<l>find_bar_code (Image, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings)</l>
<c></c>
<l>stop ()</l>
<c>* 处理图像基本代码框架</c>
<l>dev_update_off ()</l>
<l>dev_close_window ()</l>
<l>read_image (Image, 'claudia')</l>
<l>get_image_size (Image, Width, Height)</l>
<l>dev_open_window (0, 0, Width, Height, 'black', WindowHandle)</l>
<l>dev_set_draw ('margin') //规定后面图像显示的方式(填充,还是边框显示)</l>
<l>dev_set_line_width (3) // 规定后续画图线宽</l>
<l>emphasize (Image, ImageEmphasize, 5, 5, 1) // 图像增强处理</l>
<l>dev_display (ImageEmphasize) //显示图像</l>
<l>set_display_font (WindowHandle, 16, 'mono', 'true', 'false') //规定图形窗口中出现文字的大小字体,是否斜体等</l>
<l>dev_disp_text ('hello', 'image', 230, 140, 'red', [], []) //在窗口中添加文本,注意这里第二个参数决定是相对窗口位置还是图像</l>
<l>set_display_font (WindowHandle, 16, 'mono', 'true', 'false')</l>
<l>disp_message (WindowHandle, 'Hello World', 'window', 230, 140, 'black', 'true') // 一种更灵活的显示文本方式</l>
<l>* disp_message (WindowHandle, ['Hello','world!'], 'window', 12, 120, 'white', ['blue','false'])</l>
<l>stop ()</l>
<c></c>
<c>* 图像基本预处理</c>
<c>* mean_image、gauss_filter、binomial_filter:消除噪声</c>
<c>* median_image:抑制小斑点、细线</c>
<c>* smooth_image、anisotropic_diffusion:图像平滑</c>
<c>* 腐蚀:对边界向内部收缩,消除边界点,去除小元素</c>
<c>* 膨胀:对边界向外部扩充,填充空洞;</c>
<c>* opening_circle:先腐蚀后膨胀,去除孤立点、毛刺,消除小物体、平滑较大物体边界,同时不改变面积</c>
<c>* closing_circle:先膨胀后腐蚀,填充物体内部细小空洞,连接临近物体、平滑边界,同时不改变面积</c>
<c></c>
<c>* 图像分割</c>
<l>rgb1_to_gray (ImageEmphasize, GrayImage)</l>
<l>threshold (GrayImage, Regions, 4, 72)</l>
<l>connection (Regions, Connection)</l>
<l>select_shape (Connection, SelectedRegions, 'area', 'and', 25273.4, 45352.9)</l>
<l>count_obj (SelectedRegions, Number) // 计算分割区域有几个对象</l>
<l>area_center (SelectedRegions, Area, Row, Column) //区域面积的一些参数</l>
<l>fill_up (SelectedRegions, RegionFillUp) //填充目标区域</l>
<l>stop()</l>
<c></c>
<c>* 轮廓处理</c>
<c>* 提取指定图像的外轮廓</c>
<l>gen_contour_region_xld (Connection, Contours, 'border') </l>
<c>* 将轮廓线分为多个部分</c>
<l>segment_contours_xld (Contours, ContoursSplit, 'lines_circles', 5, 4, 2)</l>
<c>* 通过不同的特征,提取出分割后轮廓中满足要求的轮廓线段</c>
<l>select_contours_xld (ContoursSplit, SelectedContours, 'contour_length', 0.5, 200, -0.5, 0.5)</l>
<c>* 从轮廓线段集合中选择指定线段</c>
<l>select_obj (SelectedContours, ObjectSelected,1)</l>
<c>* 获取指定轮廓上点的像素坐标</c>
<l>get_contour_xld (ObjectSelected, Row, Col)</l>
<c>* 将位于轮廓线 Region 内的图像提取出来</c>
<l>* reduce_domain (Image, Region, ImageReduced)</l>
<l>stop ()</l>
<c></c>
<c></c>
<c>* 基于形状的模板匹配</c>
<l>dev_update_off ()</l>
<l>dev_close_window ()</l>
<c as_id="image_acquisition" as_name="Image Acquisition 01" as_grp="[1,1]" as_ord="1">* Image Acquisition 01: Code generated by Image Acquisition 01</c>
<l as_id="image_acquisition" as_name="Image Acquisition 01" as_grp="[2,1]" as_ord="1">read_image (Image1, 'C:/Users/Public/Documents/MVTec/HALCON-19.11-Progress/examples/images/for5.png')</l>
<l>gen_rectangle1 (ROI_0, 240, 196, 336, 537)</l>
<l>reduce_domain (Image1, ROI_0, ImageReduced1)</l>
<c>* 创建模板</c>
<l>create_shape_model (ImageReduced1, 'auto', -0.39, 0.79, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)</l>
<c>* 得到模板的轮廓</c>
<l>get_shape_model_contours (ModelContours, ModelID, 3)</l>
<c as_id="image_acquisition" as_name="Image Acquisition 02" as_grp="[1,1]" as_ord="1">* Image Acquisition 02: Code generated by Image Acquisition 02</c>
<l as_id="image_acquisition" as_name="Image Acquisition 02" as_grp="[2,1]" as_ord="1">read_image (Image2, 'C:/Users/Public/Documents/MVTec/HALCON-19.11-Progress/examples/images/for6.png')</l>
<c></c>
<c>* 在另一幅图像中寻找模板对应的区域</c>
<l>find_shape_model (Image2, ModelID, -0.39, 0.79, 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row3, Column3, Angle, Score)</l>
<c>* 确定匹配位置的轮廓</c>
<l>vector_angle_to_rigid (Row3, Column3, Angle, Row3, Column3, Angle, HomMat2D)</l>
<l>stop ()</l>
<c></c>
<c>* 批量导入图片</c>
<l>dev_update_off ()</l>
<l>dev_clear_window ()</l>
<l>list_image_files ('C:/Users/94960/Desktop/JISOO吖', 'default', [], ImageFiles)</l>
<l>for i:=0 to 4 by 1</l>
<l> read_image (Image3, ImageFiles[i])</l>
<l>endfor</l>
<l>stop()</l>
<c></c>
<c>* 局部阈值</c>
<l>read_image (Image4, ImageFiles[3])</l>
<l>mean_image (Image4, ImageMean, 5, 5) //中值滤波</l>
<c>* 这个算子的意思是比较原始图像和经过平滑处理图像之间5灰度值一组的灰度差,并把更暗的部分提取出来</c>
<l>dyn_threshold (Image4, ImageMean, RegionDynThresh, 5, 'dark')</l>
<c></c>
<c>* 频域滤波</c>
<l>get_image_size (Image4, Width, Height)</l>
<l>decompose3 (Image4, R, G, B) //分离成3个通道,每个通道一幅图</l>
<l>rft_generic (B, ImageFFT, 'to_freq', 'none', 'complex', Width)</l>
<l>gen_gauss_filter (ImageGauss, 100, 100, 0, 'n', 'rft', Width, Height)</l>
<l>convol_fft (ImageFFT, ImageGauss, ImageConvol)</l>
<l>rft_generic (ImageConvol, ImageFFT1, 'from_freq', 'none', 'byte', Width)</l>
<l>sub_image (B, ImageFFT1, ImageSub, 2, 100)</l>
<c></c>
<c></c>
<c>* contour 类型,光滑线型,不填充</c>
<c>* 普通矩形,填充,光滑</c>
<l>gen_rectangle1 (Rectangle1, 30, 20, 100, 200)</l>
<c>* 旋转矩形,不填充,光滑</c>
<l>gen_rectangle2_contour_xld (Rectangle, 300, 200, 0.78540, 100.5, 20.5)</l>
<c>* 旋转矩形,填充,锯齿</c>
<l>gen_rectangle2 (Rectangle2, 300, 200, 0.78540, 100, 20)</l>
<c></c>
<c>* 多边形,不填充,光滑</c>
<l>gen_contour_polygon_xld (Contour, rows, cols)</l>
<c>* 多边形,不填充,光滑</c>
<l>gen_polygons_xld (Contour, Polygons, 'ramer', 2)</l>
<c>* 多边形,不填充,锯齿</c>
<l>gen_region_polygon (Region2, rows, cols)</l>
<c>* 多边形(填充,有锯齿)</c>
<l>gen_region_polygon_filled (Region1, rows, cols)</l>
<c></c>
<c>* 普通椭圆,填充,锯齿</c>
<l>gen_ellipse (Ellipse, 200, 200, 0, 100, 60)</l>
<c>* 扇形椭圆,填充,锯齿</c>
<l>gen_ellipse_sector (EllipseSector, 200, 200, 0.78540, 100, 50, 0, 6.28318)</l>
<c>* 旋转椭圆,不填充,光滑</c>
<l>gen_ellipse_contour_xld (ContEllipse, 200, 200, 0.78540, 100, 50, 0, 6.28318, 'positive', 1.5)</l>
<c></c>
<c>* 普通圆,填充,锯齿</c>
<l>gen_circle (Circle, 200, 200, 100.5)</l>
<c>* 扇形圆,填充,锯齿</c>
<l>gen_circle_sector (CircleSector, 200, 200, 100.5, 0, 1.57080)</l>
<c>* 圆形,不填充,光滑</c>
<l>gen_circle_contour_xld (ContCircle, 200, 200, 100, 0, 6.28318, 'positive', 1)</l>
<c></c>
<c>* 通用,将 XLD contour 转成 region</c>
<l>gen_region_contour_xld (ContEllipse, Region, 'filled')</l>
<c></c>
<c>* 抠图</c>
<l>reduce_domain (Image, Region, ImageReduced)</l>
<c></c>
<c></c>
</body>
<docu id="main">
<parameters/>
</docu>
</procedure>
</hdevelop>