halcon案例text_line_slant

隶属于:
C:\Users\Public\Documents\MVTec\HALCON-23.05-Progress\examples\hdevelop\OCR\Segmentation

此例,主要针对倾斜字体时候的字符角度text_line_slant获取和hom_mat2d_slant旋转,以及partition_dynamic字符分割。字符获取方式可借鉴。对原区域进行膨胀腐蚀并和原区域求交集,可有效获取字符区域。

读图
1
提取字符区域
可借鉴:可以让碎字符也连接起来
threshold (ImageRectified, Region, 0, 100)
erosion_circle (Region, RegionErosion, 1.5)
dilation_rectangle1 (RegionErosion, RegionDilation, 1, 20)
connection (RegionDilation, ConnectedRegions)
intersection (ConnectedRegions, Region, RegionIntersection)
1
获取外界矩形
1
partition_dynamic (RegionIntersection, Characters, 30, 20)
分割字符
2
获取字符角度
text_line_slant (Image, Image, 50, rad(-45), rad(45), SlantAngle)
矩阵
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_slant (HomMat2DIdentity, -SlantAngle, ‘x’, 0, 0, HomMat2DSlant)
仿射变换
affine_trans_image (Image, ImageRectified, HomMat2DSlant, ‘constant’, ‘true’)
角度转正

1
字符区域
1

partition_dynamic (RegionIntersection, Characters, 30, 20)
分割字符
获取外界矩形
1

dev_update_off ()
read_image (Image, 'dot_print_slanted')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width * 3, Height * 3, 'black', WindowHandle)
dev_set_draw ('margin')
dev_set_colored (12)
dev_set_line_width (3)
for J := 0 to 1 by 1
    set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
    if (J == 1)
        * Correct slant
        text_line_slant (Image, Image, 50, rad(-45), rad(45), SlantAngle)
        hom_mat2d_identity (HomMat2DIdentity)
        hom_mat2d_slant (HomMat2DIdentity, -SlantAngle, 'x', 0, 0, HomMat2DSlant)
        affine_trans_image (Image, ImageRectified, HomMat2DSlant, 'constant', 'true')
    else
        copy_obj (Image, ImageRectified, 1, 1)
    endif
    *分割字符
    threshold (ImageRectified, Region, 0, 100)
    erosion_circle (Region, RegionErosion, 1.5)
    dilation_rectangle1 (RegionErosion, RegionDilation, 1, 20)
    connection (RegionDilation, ConnectedRegions)
    intersection (ConnectedRegions, Region, RegionIntersection)
    partition_dynamic (RegionIntersection, Characters, 30, 20)
    smallest_rectangle1 (Characters, Row1, Column1, Row2, Column2)
    dev_clear_window ()
    dev_display (ImageRectified)
    gen_rectangle1 (CharRectangles, Row1, Column1, Row2, Column2)
    dev_display (CharRectangles)
    if (J == 1)
        disp_message (WindowHandle, 'Segmentation with slant correction', 'window', 12, 12, 'forest green', 'true')
    else
        disp_message (WindowHandle, 'Segmentation without slant correction', 'window', 12, 12, 'red', 'true')
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值