摘要
halcon识别一维码识别步骤如下:
1.图像采集
2.预处理
3.识别条码: (1)创建条码模型
(2)设置参数(非必要)
(3)解码
4.识别并显示
5.清除模型
一维码类型
黑底白纹的一维码
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
*1 图像采集
read_image (Image, '1.bmp')
*2预处理
scale_image (Image, ImageScaled, 6.89189, -55)
*3识别条码:创建条码模型>设置参数>解码
create_bar_code_model ([], [], BarCodeHandle)
invert_image (ImageScaled, ImageInvert)
find_bar_code (ImageInvert, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings1)
*4识别并显示
dev_display (Image)
dev_set_draw ('margin')
dev_display (SymbolRegions)
set_display_font (WindowHandle, 30, 'mono', 'true', 'false')
disp_message (WindowHandle, DecodedDataStrings1, 'window', 12, 12, 'black', 'true')
*5清除模型
clear_bar_code_model (BarCodeHandle)
分辨率过高的一维码
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
*1 图像采集
read_image (Image, '2.bmp')
*2预处理:降低图片分辨率
zoom_image_factor (Image, ImageZoomed, 0.5, 0.5, 'constant')
scale_image (ImageZoomed, ImageScaled, 3.31169, -566)
*3识别条码:创建条码模型>设置参数>解码
create_bar_code_model ([], [], BarCodeHandle)
*set_bar_code_param (BarCodeHandle, 'majority_voting', 'true')
find_bar_code (ImageScaled, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings)
*4识别并显示
dev_display (ImageZoomed)
dev_set_draw ('margin')
dev_display (SymbolRegions)
set_display_font (WindowHandle, 30, 'mono', 'true', 'false')
disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'true')
*5清除模型
clear_bar_code_model (BarCodeHandle)
有干扰的一维码
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
*1 图像采集
read_image (Image, '5.bmp')
*2预处理
scale_image (Image, ImageScaled1, 28.3333, -2068)
*3识别条码:创建条码模型>设置参数>解码
create_bar_code_model ([], [], BarCodeHandle)
find_bar_code (ImageScaled1, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings1)
*4识别并显示
dev_display (Image)
dev_set_draw ('margin')
dev_display (SymbolRegions)
set_display_font (WindowHandle, 30, 'mono', 'true', 'false')
disp_message (WindowHandle, DecodedDataStrings1, 'window', 12, 12, 'black', 'true')
*5清除模型
clear_bar_code_model (BarCodeHandle)
环形一维码
本案例使用Halcon自带例程:circular_barcode
柱状一维码
本案例使用Halcon自带例程:grid_rectification
基本思路就是,先将一维码拉直,再根据摘要中的步骤;
#总结
如有错误欢迎指正,共同进步!