zoukankan      html  css  js  c++  java
  • 说说text_line_orientation算子的巧妙应用

    那天正巧在看Halcon的自带例子determine_wafer_rotation_angle.hdev,看到text_line_orientation算子的一个应用。

    原本这个算子是用来确定字符文本的文字排列方向。算子描述如下:

    text_line_orientation(Region, Image : : CharHeight, OrientationFrom, OrientationTo : OrientationAngle)
    目的:确定文本行或段落的方向。
    参数一(input_object):文本行区域。可以自己画一个矩形区域,也可以直接输入整个图片为文本行区域
    参数二(input_object):输入图像
    参数三(input_object):文本行的高度
    参数四(input_object):文本行的最小旋转角度
    参数五(input_object):文本行最大旋转角度
    参数六(output_control) :得到的计算的文本行旋转角度。也是我们做需要的,之后对图形文字进行旋转或仿射变换时需要用到该参数

    但是在例子中:
    '''
    dev_update_off ()
    dev_close_window ()
    read_image (Image, 'wafer/wafer_rotated')
    dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
    set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
    dev_set_draw ('margin')
    *

    • The coordinates of the center of rotation can be determined
    • e.g. by using the operator optical_flow_mg.
    • See also the example: rotation_from_optical_flow.hdev
      RotCenterRow := 360.13
      RotCenterCol := 359.99
      gen_cross_contour_xld (Cross, RotCenterCol, RotCenterCol, 20, 0.785398)
      gen_rectangle1 (Rectangle, RotCenterRow - 55, RotCenterCol - 300, RotCenterRow + 55, RotCenterCol + 300)
      dev_display (Image)
      dev_set_line_width (3)
      dev_set_color ('yellow')
      dev_display (Rectangle)
      dev_set_line_width (2)
      dev_set_color ('white')
      dev_display (Cross)
      disp_message (WindowHandle, 'Determine the angle of rotation of the wafer by using the area around the center of rotation', 'window', 12, 12, 'black', 'true')
      disp_continue_message (WindowHandle, 'black', 'true')
      stop ()
    • Determine the angle of rotation of the wafer to
    • correct the alignment
      reduce_domain (Image, Rectangle, ImageReduced)
      text_line_orientation (Rectangle, ImageReduced, 25, rad(-30), rad(30), OrientationAngle)
      Angle := -deg(OrientationAngle)
      rotate_image (Image, ImageRotate, Angle, 'constant')
    • Display the results
      dev_clear_window ()
      dev_display (ImageRotate)
      dev_set_line_width (3)
      dev_set_color ('yellow')
      dev_display (Rectangle)
      dev_set_line_width (2)
      dev_set_color ('white')
      dev_display (Cross)
      disp_message (WindowHandle, 'The wafer must be rotated by ' + Angle$'.2f' + '° to be correctly aligned', 'window', 12, 12, 'black', 'true')
      '''

    从头到尾,和文字处理没有任何关系,但是不妨碍算子精准得到Die的排列方向,然后按此角度进行rotate_image操作,完美完成示例。

    深入思考一下,从算子反推,文字的排列是有一个规律的,
    首先,高度是差不多的。
    其次,每个字符的宽度都是相差不太大的。
    最后,每个字符间有间隔。
    由此,推测,算子基于上面的特征计算文本的方向。
    推演一下,只要区域内满足以上的特征的,都可以尝试下应用这个算子得到方向,实例中Die的排列是规则而有序的。
    应用此算子,完美匹配。


    看了感觉怎么样?来说说吧。。。
    喜欢记得关注起来!赶紧的。


  • 相关阅读:
    在pytorch中使用可视化工具visdom
    3"GAN-GAN实战:GD的实现
    31:GAN-js散度的缺陷以及解决办法:WGAN的提出
    31:GAN-DCGAN(deconvolution GAN逆卷积操作)以及JS散度的缺陷
    31:GAN-纳什均衡
    31:GAN-GAN原理
    30:无监督学习-自编码网络的变种
    30:无监督学习-自编码(Auto-Encoder简称AE)原理
    如何打印网络的参数量
    29:迁移学习(当数据集比较小时,可以使用迁移学习达到一个更好的效果)
  • 原文地址:https://www.cnblogs.com/eyesonchip/p/13725483.html
Copyright © 2011-2022 走看看