*读入图像
read_image (Image11, 'C:/Users/gwd/Desktop/1.1.bmp')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_display (Image11)
rgb1_to_gray (Image11, GrayImage)
*提取内外圆的半径
threshold (GrayImage, Regions, 0, 111)
shape_trans (Regions, outcircle, 'outer_circle')
*返回一个区域的补集
complement (Regions, RegionComplement)
connection (RegionComplement, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 1.56034e+006, 2.66379e+006)
smallest_circle (Regions, Row, Column, OuterRadius)
smallest_circle (SelectedRegions, Row1, Column1, InnerRadius)
polar_trans_image_ext (Image11, PolarTransImage, Row, Column, rad(360), 0, OuterRadius-100, InnerRadius+40, 1440, 100, 'bilinear')
rgb1_to_gray (PolarTransImage, GrayImage1)
invert_image (PolarTransImage, ImageInvert)
scale_image (ImageInvert, ImageScaled, 6.71053, -1429)
binary_threshold (ImageScaled, Region, 'max_separability', 'light', UsedThreshold)
connection (Region, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 43.94, 500)
union1 (SelectedRegions1, RegionUnion)
*若改成,11,,11 则C会被识别成G
dilation_rectangle1 (RegionUnion, RegionDilation, 6, 6)
connection (RegionDilation, ConnectedRegions2)
intersection (ConnectedRegions2, Region, RegionIntersection)
sort_region (RegionIntersection, SortedRegions, 'character', 'true', 'row')
read_ocr_class_mlp ('Industrial_0-9A-Z_NoRej.omc', OCRHandle)
do_ocr_multi_class_mlp (SortedRegions, GrayImage1, OCRHandle, Class, Confidence)
stop ()
*显示
count_obj (SortedRegions, Number)
area_center (SortedRegions, Area, Row2, Column2)
for i := 1 to Number by 1
disp_message (WindowHandle, Class[i-1], 'PolarTransImage', 40, Column2[i-1]-20, 'red', 'true')
endfor
基于Halcon学习的OCR识别【三】----圆环字符
于 2022-01-15 20:59:36 首次发布