Index:.../Applications/OCR/ocr_wafer_semi_font.hdev
*
* This example describes one step from the semiconductor product chain.
* In the front-end-of-line step, the ICs are printed on the wafer. To
* tag a single wafer from the production life line, each wafer receives
* an ID number, printed with the SEMI font. This ID number is read here.
*
dev_update_off ()
dev_close_window ()
read_image (Image, 'ocr/wafer_semi_font_01')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_set_draw ('margin')
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_line_width (2)
dev_set_colored (12)
设置的颜色挺多的
*
read_ocr_class_mlp ('SEMI', OCRHandle)
用的是semi训练模板
NumImages := 10
for Index := 1 to NumImages by 1
*
* Segment characters
read_image (Image, 'ocr/wafer_semi_font_' + Index$'02')
* Characters must be black-on-white, i.e., dark characters on a light background
invert_image (Image, ImageInvert)
mean_image (Image, ImageMean, 31, 31)
dyn_threshold (Image, ImageMean, RegionDynThresh, 7, 'light')
dynthreshold提取字符
* Characters are often dotted. Therefore, we first merge close dots
* that belong to the same character just before calling the operator connection
closing_circle (RegionDynThresh, RegionClosing, 2.0)
但字符各种点,做了closing闭操作,很常用要熟悉
connection (RegionClosing, ConnectedRegions)
* Filter out characters based on two facts:
* 1. Characters are printed in SEMI-12. Therefore we can make strong assumptions
* on the dimensions of the characters
* 2. Characters are printed along a straight line
select_shape (ConnectedRegions, SelectedRegions1, ['height','width'], 'and', [29,15], [60,40])
提取方法比较固定,想必因为这一系列图的字符所占像素点差不多大小
area_center (SelectedRegions1, Area, RowCh, ColumnCh)
MedianRow := median(RowCh)
中位数,这里很有意义,我们都学过统计,当出现这种一串稳定数据,里面有几个不稳定值时,该用哪种统计方法解决问题?
虽然大家都会,但解决问题时能不能想出来,则是关键了
select_shape (SelectedRegions1, Chars, 'row', 'and', MedianRow - 30, MedianRow + 30)
用中位数(坐标)来提取字符就很稳定了
*
* Read out segmented characters
sort_region (Chars, CharsSorted, 'character', 'true', 'column')
shape_trans (CharsSorted, Characters, 'rectangle1')
排序后把字符外接矩阵做出来,shape-trans
do_ocr_multi_class_mlp (Characters, ImageInvert, OCRHandle, Class, Confidence)
做匹配,关键还是halcon匹配算法太牛了,虽然实际用慢多了,但例程都快狠准
*
下面全是显示代码
dev_display (ImageInvert)
dilation_rectangle1 (Characters, RegionDilation, 7, 7)
dev_display (RegionDilation)
area_center (CharsSorted, Area1, Row, Column)
MeanRow := mean(Row)
for IndexL := 0 to |Class| - 1 by 1
disp_message (WindowHandle, Class[IndexL], 'image', MeanRow + 40, Column[IndexL] - 20, 'black', 'true')
endfor
if (Index != NumImages)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
clear_ocr_class_mlp (OCRHandle)