隶属于:
C:\Users\Public\Documents\MVTec\HALCON-23.05-Progress\examples\hdevelop\OCR\Segmentation
此例,主要是点状字符的提取。一个有角度的字符,通过text_line_orientation获取字符角度,再旋转图片,图像Blob分析得到字符区域并显示。
读图
原图转正
进行点图处理
灰度值拉伸
二值化初步提取字符区域
再进一步提取字符区域
将字符扩大,选出真正的字符区域
得到单个字符的外接区域
膨胀得到字符外界区域
求矩形和点状区域
显示。
显示可借鉴:颜色这么传入即可
dev_set_color ([‘green’, ‘cyan’])
dev_display (RegionDots)
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, 400, 300, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (2)
for J := 1 to 5 by 1
read_image (Image, 'dot_print_rotated/dot_print_rotated_' + J$'02d')
text_line_orientation (Image, Image, 48, rad(-30), rad(30), OrientationAngle)
rotate_image (Image, ImageRotate, -OrientationAngle / rad(180) * 180, 'constant')
dots_image (ImageRotate, ImageDots, 3, 'dark', 2)
scale_image_max (ImageDots, ImageScaleMax)
intensity (ImageRotate, ImageRotate, Mean, Deviation)
threshold (ImageScaleMax, RegionThresh, Mean - 35, 255)
connection (RegionThresh, ConnectedDots)
select_shape (ConnectedDots, SelectedDots, 'area', 'and', 8, 1000)
opening_circle (SelectedDots, SelectedDotsOpening, 1.5)
union1 (SelectedDotsOpening, Region)
closing_circle (Region, RegionClosing, 9.5)
connection (RegionClosing, ConnectedRegions)
* 连接分割的部分。
smallest_rectangle1 (ConnectedRegions, Row11, Column11, Row21, Column21)
gen_rectangle1 (Rectangle1, Row11, Column11, Row21, Column21)
union1 (Rectangle1, RegionUnion3)
connection (RegionUnion3, ConnectedRegions2)
select_shape (ConnectedRegions2, SelectedRegions, ['area', 'height', 'width'], \
'and', [1000, 30, 20], [3200, 70, 70])
* 获取矩形形状。
smallest_rectangle1 (SelectedRegions, Row1, Column1, Row2, Column2)
gen_rectangle1 (RectangularShape, Row1, Column1, Row2, Column2)
*构建线条
union1 (SelectedRegions, RegionUnion)
dilation_rectangle1 (RegionUnion, RegionDilation, 50, 1)
connection (RegionDilation, ConnectedLines)
select_shape (ConnectedLines, SelectedLines, 'area', 'and', 10000, 99999)
* 线条的元素。
intersection (SelectedLines, RectangularShape, ElementOfLines)
intersection (ElementOfLines, SelectedDotsOpening, RegionDots)
dev_clear_window ()
dev_display (ImageRotate)
dev_set_color ('gray')
dev_display (ElementOfLines)
dev_set_color (['green', 'cyan'])
dev_display (RegionDots)
*
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endfor