*这个应用展示了半导体生产线中的一环,在把ic印在晶片的前道工序中,为晶片打上一个IDnumber,用的是半导体字体
*在这个应用中,也展示了读取IDnumber
* 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)
*设置显示颜色为12色
dev_set_colored (12)
* 读取训练好的OCR文件
read_ocr_class_mlp (‘SEMI_NoRej.omc‘, OCRHandle)
*图片数量为10张
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‘)
*字符通常是点印的,所以,在联通区域之前,我们先做一个闭运算把字符区域连起来
* 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)
*联通区域
connection (RegionClosing, ConnectedRegions)
*筛选字符基于两个事实
* Filter out characters based on two facts:
*字符由SEMI-12打印,所以我们可以大胆假设猜想字符的尺寸
* 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)
*根据Row坐标筛选字符
select_shape (SelectedRegions1, Chars, ‘row‘, ‘and‘, MedianRow - 30, MedianRow + 30)
* 读取出分割的字符
* Read out segmented characters
*本地函数,增强对比度
enhance_contrast (Chars, ImageInvert, ImageRead)
*根据字符顺序排列区域
sort_region (Chars, CharsSorted, ‘character‘, ‘true‘, ‘column‘)
*执行多字符OCR识别
do_ocr_multi_class_mlp (CharsSorted, ImageRead, OCRHandle, Class, Confidence)
* 显示反转的图像
dev_display (ImageInvert)
*显示排列的字符
dev_display (CharsSorted)
*求出排列字符的区域和中心坐标
area_center (CharsSorted, Area1, Row, Column)
MeanRow := mean(Row)
*显示信息(一行黑色,一行黄色,黄色作为背景)
disp_message (WindowHandle, Class, ‘image‘, MeanRow + 42, Column - 11, ‘yellow‘, ‘false‘)
disp_message (WindowHandle, Class, ‘image‘, MeanRow + 40, Column - 10, ‘slate blue‘, ‘false‘)
*如果图像没有处理完就继续
if (Index != NumImages)
disp_continue_message (WindowHandle, ‘black‘, ‘true‘)
stop ()
endif
endfor
*清除句柄,释放内存
clear_ocr_class_mlp (OCRHandle)
原文:https://www.cnblogs.com/HomeSapiens/p/13526908.html