Halcon条码二维码识别和测量

本文介绍了条形码和二维码的识别流程,包括模型初始化、参数设置、条码搜索解析及结果处理等步骤,并展示了如何使用图像处理技术来测量芯片引脚的宽度。
*条形码识别
read_image (Image, 'barcode/25industrial/25industrial01')
dev_display (Image)
*创建条码识别函数
*'stop_after_result_num':通用参数名字, 1:通用参数值
create_bar_code_model ('stop_after_result_num', 1, BarCodeHandle)
*create_bar_code_model ([], [], BarCodeHandle)
*set_bar_code_param (BarCodeHandle, 'stop_after_result_num', 1)
*==
*create_bar_code_model ('stop_after_result_num', 1, BarCodeHandle)
*搜索条码并解析
*SymbolRegions:识别成功后条形码所在的区域,  'auto':码制, DecodedDataStrings:识别结果
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings)
get_bar_code_param (BarCodeHandle, 'element_size_min', GenParamValues)
*获取识别区域BarCodeObjects
get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'candidate_regions')
*获取识别的结果BarCodeResults
get_bar_code_result (BarCodeHandle, 'all', 'decoded_strings', BarCodeResults)
*清除条码模型
clear_bar_code_model (BarCodeHandle)
*1、模型初始化
* create_bar_code_model
* set_bar_code_param//条形码参数设置
* set_bar_code_param_specific
*2、条码识别
* find_bar_code
*3、结果处理
* get_bar_code_object
* get_bar_code_param
* get_bar_code_result    
*4、清除模型
* clear_bar_code_model  
*二维码识别
read_image (Image2d, 'datacode/ecc200/ecc200_print_quality_01')
dev_display (Image2d)
*创建二维码的模型函数
*'QR Code':码制, [], []:检测方式的参数及对应的值[]为自动确定
create_data_code_2d_model ('Data Matrix ECC 200', [], [], DataCodeHandle)
*识别,SymbolXLDs:二维码的区域DecodedDataStrings2d识别结果
find_data_code_2d (Image2d, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings2d)
*清除模型
clear_data_code_2d_model (DataCodeHandle)
*1、模型初始化
* create_data_code_2d_model
* set_data_code_2d_param//二维码参数设置
*2、条码识别
* find_data_code_2d
*3、结果处理
* get_data_code_2d_object
* get_data_code_2d_param
* get_data_code_2d_result
*4、清除模型
* clear_data_code_2d_model
*测量(识别芯片引脚宽度)
read_image (Image, 'ic_pin')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width / 2, Height / 2, 'black', WindowHandle)
dev_display (Image)
Row := 47
Column := 485
Phi := 0
Length1 := 420
Length2 := 10
dev_set_draw ('margin')
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
*Row, Column, Phi, Length1, Length2为测量矩形的参数
*Width, Height为要处理的图像宽高,单位是像素
*'nearest_neighbor':近邻插值方法,MeasureHandle:该测量矩形的句柄
gen_measure_rectangle2 (Row, Column, Phi, Length1, Length2, Width, Height, 'nearest_neighbor', MeasureHandle)
for ii := 1 to 100 by 1
    *1.5:平滑系数;30:最小边缘幅度;'negative':负的边缘,由亮到暗的边缘对;all:选择全部边缘对;
    *RowEdgeFirst,ColumnEdgeFirst:边缘对中第一条边缘的中心坐标,从测量方向的起点方向开始
    *AmplitudeFirst:第一个边缘的振幅(幅度值,灰度值)
    *RowEdgeSecond, ColumnEdgeSecond:边缘对中第二条边缘的中心坐标,从测量方向的起点方向开始
    *AmplitudeSecond:第二个边缘的振幅(幅度值,灰度值)
    *PinWidth:边缘对的宽度,PinDistance:相邻连续两个边缘对之间的距离
    *注:以上所有参数都是基于亚像素,像素级别是浮点型的
    measure_pairs (Image, MeasureHandle, 1.5, 30, 'negative', 'all', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, PinWidth, PinDistance)
endfor
*measure_pos (Image, MeasureHandle, 1, 30, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distance)
Row1 := 0
Column1 := 100
Row2 := 100
Column2 := 200
dev_set_part (Row1, Column1, Row2, Column2)
dev_display (Image)
disp_line (WindowHandle, RowEdgeFirst, ColumnEdgeFirst, RowEdgeSecond, ColumnEdgeSecond)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值