halcon一维码和二维码识别自定义函数

1.一维码自定义函数

一维码识别自定义函数:

lib_find_1D_barcode (Image, Contour, Roi, Row, Column, Barcode)

函数对应参数如下图:

 函数内容:

try
    gen_empty_obj (Contour)
    Row := []
    Column := []
    Barcode := 'NA'
    
    gen_rectangle1 (Rectangle, Roi[0], Roi[1], Roi[2], Roi[3])
    reduce_domain (Image, Rectangle, ImageReduced)
   *创建条码模型
    create_bar_code_model ([], [], BarCodeHandle)
    *设置参数
*     set_bar_code_param (BarCodeHandle, 'element_size_min', 4)
*     set_bar_code_param (BarCodeHandle, 'element_size_max', 32)
*     set_bar_code_param (BarCodeHandle, 'check_char', 'present')
*     set_bar_code_param (BarCodeHandle, 'persistence', 1)
*     set_bar_code_param (BarCodeHandle, 'num_scanlines', 10)
*     set_bar_code_param (BarCodeHandle, 'start_stop_tolerance', 'high')
*     set_bar_code_param (BarCodeHandle, 'orientation', 0)
*     set_bar_code_param (BarCodeHandle, 'orientation_tol', 20)
*     set_bar_code_param (BarCodeHandle, 'element_height_min', 100)
*     set_bar_code_param (BarCodeHandle, 'stop_after_result_num', 0)
 
   *解码

    find_bar_code (ImageReduced, Contour, BarCodeHandle, ['Code 128','Code 39'], BarCodeStrings)
    
*     get_bar_code_param (BarCodeHandle, 'element_size_min', GenParamValue)
    
*     get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'candidate_regions')
    
*     get_bar_code_result (BarCodeHandle, 'all', 'decoded_types', BarCodeResults)
*     get_bar_code_result (BarCodeHandle, 0, 'quality_isoiec15416', Quality)
     if( BarCodeStrings != [])
        Barcode :=   BarCodeStrings[0] 
        area_center_xld (Contour, Area, Row, Column, PointOrder)
        gen_cross_contour_xld (CrossCenter, Row, Column, sqrt(Area)/2, 0)
        concat_obj (Contour, CrossCenter, Contour)
    endif
 
catch (Exception)
endtry

try
   *清除条码模型
    clear_bar_code_model (BarCodeHandle)
catch (Exception)
endtry


return ()

2.二维码自定义函数

二维码识别自定义函数:

lib_find_2D_barcode(Image, Contour, Roi, Row, Column, Barcode)

函数对应参数如下图:

 函数内容:

try
    gen_empty_obj (Contour)
    Row := []
    Column := []
    Barcode := 'NA'

    gen_rectangle1 (Rectangle, Roi[0], Roi[1], Roi[2], Roi[3])
    reduce_domain (Image, Rectangle, ImageReduced)
*     create_data_code_2d_model ('Data Matrix ECC 200', 'default_parameters', 'enhanced_recognition', DataCodeHandle)
*     find_data_code_2d (ImageReduced, Contour, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)

    create_data_code_2d_model ('Data Matrix ECC 200', 'default_parameters', 'enhanced_recognition', DataCodeHandle)
    find_data_code_2d (ImageReduced, Contour, DataCodeHandle, 'train', 'all', ResultHandles, DecodedDataStrings)

    if (DecodedDataStrings != [])
        Barcode := DecodedDataStrings[0]
        area_center_xld (Contour, Area, Row, Column, PointOrder)
        gen_cross_contour_xld (CrossCenter, Row, Column, sqrt(Area)/2, 0)
        concat_obj (Contour, CrossCenter, Contour)
    endif
catch (Exception)
endtry

try
    clear_data_code_2d_model (DataCodeHandle)
catch (Exception)
endtry


return ()

以上就是我自定义创建的函数,方便后面调用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

susan花雨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值