Barcode读取之circularly_barcode.hdev

*识别环形打印的条码

  • Read circularly printed bar codes.
  • 关闭窗体
    dev_update_off ()
    *获取系统参数
    get_system (‘clip_region’, Information)
    *设置系统参数
    set_system (‘clip_region’, ‘true’)
    *读取图像
    read_image (Image, ‘circular_barcode’)
    *获取图像尺寸
    get_image_size (Image, Width, Height)
    *关闭窗体
    dev_close_window ()
    *打开窗体
    dev_open_window (0, 0, Width / 2, Height / 2, ‘black’, WindowHandle)
    *设置显示颜色为12色
    dev_set_colored (12)
    *显示图像
    dev_display (Image)
    *设置显示字体
    set_display_font (WindowHandle, 14, ‘mono’, ‘true’, ‘false’)
    stop ()
  • 分割包含条码的圆环
  • Segment the ring on the CD that contains the bar code.
    *阈值分割
    threshold (Image, Region, 0, 100)
    *闭运算
    closing_circle (Region, Region, 3.5)
    *联通区域
    connection (Region, ConnectedRegions)
    *选择形状
    select_shape (ConnectedRegions, Ring, [‘width’,‘height’], ‘and’, [550,550], [750,750])
    *获取圆环的外圆
    shape_trans (Ring, OuterCircle, ‘outer_circle’)
    *求圆环之外的区域(补集)
    complement (Ring, RegionComplement)
    *联通区域
    connection (RegionComplement, ConnectedRegions)
    *根据面积特征选择形状
    select_shape (ConnectedRegions, InnerCircle, [‘width’,‘height’], ‘and’, [450,450], [650,650])
  • 定义条码圆环的一些参数
  • Determine the parameters of the ring that contains the bar code.
    *求外圆半径
    smallest_circle (Ring, Row, Column, OuterRadius)
    *求内圆半径
    smallest_circle (InnerCircle, InnerRow, InnerColumn, InnerRadius)
    *设置显示颜色为绿色
    dev_set_color (‘green’)
    *设置填充方式
    dev_set_draw (‘margin’)
    *设置线宽
    dev_set_line_width (3)
    *显示图像
    dev_display (Image)
    *显示外圆
    dev_display (OuterCircle)
    *显示内圆
    dev_display (InnerCircle)
    stop ()
  • 读取条码。通过极坐标展开来实现
  • Now read the bar code. This is done by computing the polar transformation
  • of the ring in the image that contains the bar code.
    *极坐标宽度
    WidthPolar := 1440
    *极坐标高度
    HeightPolar := round(OuterRadius - InnerRadius - 10)
    *进行极坐标变换
    polar_trans_image_ext (Image, PolarTransImage, Row, Column, rad(360), 0, OuterRadius - 5, InnerRadius + 5, WidthPolar, HeightPolar, ‘bilinear’)
    *图像反转,黑白交换(黑变白,白变黑)
    invert_image (PolarTransImage, ImageInvert)
  • 把条码区域高度放大
  • Since the bar code region is quite flat the image height is doubled.
    *放大图像
    zoom_image_factor (ImageInvert, ImageZoomed, 1, 2, ‘weighted’)
    *创建一维码读取句柄
    create_bar_code_model ([], [], BarCodeHandle)
  • 条码很小并且对比度很低,。所以阈值就从0.05到0.1
  • Bars are small and the contrast is low; therefore the threshold is raised from 0.05 to 0.1.
    *设置条码读取器参数,具体意义,前面文章有翻译
    set_bar_code_param (BarCodeHandle, ‘element_size_min’, 1.5)
    set_bar_code_param (BarCodeHandle, ‘meas_thresh’, 0.3)
    *读取条码
    find_bar_code (ImageZoomed, SymbolRegions, BarCodeHandle, ‘Code 128’, DecodedDataStrings)
    *清除条码句柄
    clear_bar_code_model (BarCodeHandle)
    *限制窗体尺寸
    dev_set_window_extents (-1, -1, WidthPolar / 2, HeightPolar)
    *显示放大条码区域
    dev_display (ImageZoomed)
    *显示条码区域
    dev_display (SymbolRegions)
    set_system (‘clip_region’, Information)
    *显示条码
    disp_message (WindowHandle, DecodedDataStrings, ‘image’, 10, 180, ‘black’, ‘true’)
    stop ()
  • 把条码区域变回到原来的样子并且在原图上显示
  • Transform the code region back to the original image and display it.
    *缩小图像到原来大小
    zoom_region (SymbolRegions, SymbolRegions, 1, 0.5)
    *变换到环形条码区域
    polar_trans_region_inv (SymbolRegions, CodeRegionCircular, Row, Column, rad(360), 0, OuterRadius - 5, InnerRadius + 5, WidthPolar, HeightPolar, Width, Height, ‘nearest_neighbor’)
    *限制窗体尺寸
    dev_set_window_extents (-1, -1, Width / 2, Height / 2)
    *显示图像
    dev_display (Image)
    *先环形条码区域
    dev_display (CodeRegionCircular)
    *显示条码
    disp_message (WindowHandle, DecodedDataStrings, ‘window’, 12, 12, ‘black’, ‘true’)

*极坐标变换原理如下

*直角坐标是我们能够直观想象,符合人类大脑的空间坐标,即x-y坐标系。

*极坐标在直角坐标系基础上,以角度θ和半径r建立的坐标系,自变量为θ,因变量为r,θ-r与x-y之间存在这一定关系。

*x = rcos(θ),

*y = rsin(θ),

*即=>>>>>

*θ = arctan(y/x)

*有些曲线在直角坐标系不容易表示,反而在极坐标系下能够很简洁的表示,特别是涉及角度的曲线,例如圆在极坐标系是一条直线,如下图所示。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值