OCR之dotprt.hdev

  • dotprt.hdev: Segmentation of a dot printing
  • 点印文字分割
    *关闭窗体更新
    dev_update_window (‘off’)
    *读取图像
    read_image (Needle, ‘needle1’)
    *关闭窗体
    dev_close_window ()
    *获取图像尺寸
    get_image_size (Needle, Width, Height)
    *打开新窗体
    dev_open_window (0, 0, 2 * Width, 2 * Height, ‘black’, WindowID)
    *设置显示窗体
    set_display_font (WindowID, 16, ‘mono’, ‘true’, ‘false’)
    *显示图像
    dev_display (Needle)
    *右下角显示’Press F5 to continue’
    disp_continue_message (WindowID, ‘black’, ‘true’)
    stop ()

Row1 := 50
Column1 := 90
Row2 := 250
Column2 := 370
Px := Column1 + (Column2 - Column1) / 2
Py := Row1 + (Row2 - Row1) / 2
*生成区域
gen_rectangle1 (Rectangle1, Row1, Column1, Row2, Column2)
dev_display (Rectangle1)

  • orientation correction
    *算出文字的倾斜方向
    text_line_orientation (Needle, Needle, 35, -0.523599, 0.523599, OrientationAngle)
    *生成一个初始矩阵
    hom_mat2d_identity (HomMat2DIdentity)
    *算出旋转转换矩阵
    hom_mat2d_rotate (HomMat2DIdentity, -OrientationAngle, Px, Py, HomMat2DRotate)
    *把图像转正,让其与极轴的夹角为0
    affine_trans_image (Needle, Rotated, HomMat2DRotate, ‘constant’, ‘false’)
    *显示图像
    dev_display (Rotated)
    *右下角显示’Press F5 to continue’
    disp_continue_message (WindowID, ‘black’, ‘true’)
    stop ()
    *阈值分割
    threshold (Rotated, RawSegmentation, 0, 105)
    *联通区域
    connection (RawSegmentation, ConnectedRegions)
    *根据面积特征选择形状
    select_shape (ConnectedRegions, MinSizeRegions, ‘area’, ‘and’, 6, 99999)
    *联合区域
    union1 (MinSizeRegions, RemovedNoise)
    *显示旋转后的图像
    dev_display (Rotated)
    *设置显示颜色为绿色
    dev_set_color (‘green’)
    *设置填充方式
    dev_set_draw (‘fill’)
    *显示噪音图像
    dev_display (RemovedNoise)
    *右下角显示’Press F5 to continue’
    disp_continue_message (WindowID, ‘black’, ‘true’)
    stop ()
    *把区域修剪成一个矩形
    clip_region (RemovedNoise, RawSegmentation, 53, 75, 260, 356)
    *显示旋转后的图像
    dev_display (Rotated)
    *显示初始分割区域
    dev_display (RawSegmentation)
    **右下角显示’Press F5 to continue’
    disp_continue_message (WindowID, ‘black’, ‘true’)
    stop ()
    *闭运算
    closing_circle (RawSegmentation, ClosedPatterns, 6)
    *矩形开运算
    opening_rectangle1 (ClosedPatterns, SplitPatterns, 1, 5)
    *联通区域
    connection (SplitPatterns, ConnPatterns)
    *根据面积特征选择形状
    select_shape (ConnPatterns, CharCandidates, ‘area’, ‘and’, 150, 5999)
    *变换形状
    shape_trans (CharCandidates, CharBlocks, ‘rectangle1’)
    *设置填充方式
    dev_set_draw (‘margin’)
    *设置线宽
    dev_set_line_width (2)
    *显示旋转图像
    dev_display (Rotated)
    *显示字符块
    dev_display (CharBlocks)
    *右下角显示’Press F5 to continue’
    disp_continue_message (WindowID, ‘black’, ‘true’)
    stop ()
    将输入区域划分为WidthHeight的矩形。矩形在参数中Partitioned 返回。
    *该区域总是被分割成近似相等大小的矩形。如果这对于所请求的矩形大小是不可能的,如果这对于所请求的矩形大小是不可能的,以便得到的矩形的大小近似相等。
    *如果该区域小于给定的大小,则其输出保持不变。只有当区域的大小至少是由参数给出的矩形大小的1.5倍时,才会进行分区。
    partition_rectangle (CharBlocks, CharCandidates, 25, 100)
    *阈值分割的区域和partition_rectangle的区域求交集.这样就把每一个字符单独分割开了
    intersection (CharCandidates, RawSegmentation, Characters)
    *闭运算
    closing_circle (Characters, IntermedCharacters, 2.5)
    *设置显示颜色
    dev_set_colored (12)
    *显示旋转图像
    dev_display (Rotated)
    *设置显示颜色
    dev_set_draw (‘fill’)
    *显示分割开的字符区域
    dev_display (IntermedCharacters)
    **右下角显示’Press F5 to continue’
    disp_continue_message (WindowID, ‘black’, ‘true’)
    stop ()
  • 生成一个空对象
    gen_empty_obj (Characters)
    获取分隔开的字符数量
    count_obj (IntermedCharacters, NumIntermediate)
    显示图像
    dev_display (Rotated)
    这段其实我觉得可以不需要
    *************这里也只是做一个显示用
    for i := 1 to NumIntermediate by 1
    dev_set_color (‘red’)
    select_obj (IntermedCharacters, Char, i)
    dev_display (Char)
    connection (Char, CharParts)
    select_shape (CharParts, CharCandidates, ‘area’, ‘and’, 40, 99999)
    union1 (CharCandidates, Char)
    dev_set_color (‘green’)
    dev_display (Char)
    concat_obj (Characters, Char, Characters)
    endfor

*通过高度筛选正确的文字
select_shape (IntermedCharacters, Heigh, ‘height’, ‘and’, 24, 50)
*排列筛选的区域
sort_region (Heigh, FinalCharacters, ‘character’, ‘true’, ‘row’)
*设置显示颜色为红色
dev_set_color (‘red’)
*设置填充方式
dev_set_draw (‘margin’)
*显示图像
dev_display (Rotated)
dev_display (FinalCharacters)
*设置显示颜色为红色
dev_set_color (‘green’)
*设置线宽
dev_set_line_width (3)
*设置显示区域形状为矩形
dev_set_shape (‘rectangle1’)
*显示最终字符区域
dev_display (FinalCharacters)
*设置显示区域形状为不变
dev_set_shape (‘original’)
*设置线宽
dev_set_line_width (1)
*设置填充方式
dev_set_draw (‘fill’)
*读取OCR文件到OCR句柄
read_ocr_class_mlp (‘DotPrint_NoRej’, OCRHandle)
*用OCR进行一次多个字符识别
do_ocr_multi_class_mlp (FinalCharacters, Rotated, OCRHandle, Class, Confidence)
*求字符区域的最小外接矩形
smallest_rectangle1 (FinalCharacters, Row11, Column1, Row2, Column21)
*显示信息
disp_message (WindowID, Class, ‘image’, Row2, Column1, ‘green’, ‘false’)
*清楚OCR句柄
clear_ocr_class_mlp (OCRHandle)
*开启窗体更新
dev_update_window (‘on’)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值