例程
一维码识别
参数
create_bar_code_model ([], [], BarCodeHandle)
set_bar_code_param (BarCodeHandle, ‘element_size_variable’, ‘false’) 为“ture”时可识别变形畸变的条形码
set_bar_code_param( : : BarCodeHandle, GenParamNames, GenParamValues : ) 设置条形码模型参数
BarCodeHandle 条形码句柄
GenParamNames 通用型参数的名字
‘element_size_min’ 条码的最小尺寸,指条码宽度和间距,大码应设大一点,减少处理时间
'element_size_max’条码的最大尺寸,不能过小也不能过大
'check_char’是否验证校验位,'absent’不检查校验和,'present’检查校验和
'persistence’设置为1,则会保留中间结果,评估条码印刷质量时会用到
'num_scanlines’解码时所用扫描线的最大数目,设置为0表示自动确定,一般设置为2-30
‘start_stop_tolerance’容许误差值,可设置为’low’或者’high’,设置为’high’可能造成误判
‘orientation’、'orientation_tol’分别指条码的方向和方向容差,设置准确可大大提高解码效率
'element_height_min’条码的最小高度,默认值-1表示自动推测条码高度,该参数对速度影响大
'stop_after_result_num’设置要解码的个数,0表示全部找出,设置为2表示找到2个就不找了
check_char 是否验证校验位(present是absent否)
composite_code 附加一个二维条码构成"组合码"
element_height_min 最小条码的高度
max_diff_orient 相邻边缘方向的最大角度容差
meas_thresh 用来识别条码边沿,一般取值[0.05,0.2]
meas_thresh_abs
min_identical_scanlines 认定成功解码所需的最少扫描线数,默认为1
num_scanlines 条码扫描的最大数目
persistence 保存解码的中间结果
start_stop_tolerance 当检测扫描线的起点和终点图案时,用该语句设置"容许误差"
upce_encodation 用以不同的输出格式(UPC-E码)
slanted 对倾斜条码额外处理
一般流程
1、 模型初始化
create_bar_code_model ([], [], BarCodeHandle)
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
* 实时
*open_framegrabber ('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '[0] ', 0, -1, AcqHandle)
*grab_image_start (AcqHandle, -1)
read_image (Image, 'D:/Documents/Desktop/halcon/9 实战项目图片/码.jpg')
create_bar_code_model ([], [], BarCodeHandle)
dev_close_window ()
dev_open_window (0, 0, 400, 400, 'black', WindowHandle)
dev_set_draw ('margin')
dev_set_line_width (3)
*while (true)
* grab_image_async (Image, AcqHandle, -1)
get_image_size (Image, Width, Height)
dev_display (Image)
set_bar_code_param (BarCodeHandle, 'meas_thresh_abs', 0)
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings)
dev_set_color ('blue')
dev_display (SymbolRegions)
disp_message (WindowHandle, DecodedDataStrings, 'window', 270, 120, 'red', 'false')
*endwhile
*close_framegrabber (AcqHandle)
clear_bar_code_model (BarCodeHandle)