Halcon スキャン コードにはバーコード、QR コードが含まれます

1. バーコード

dev_close_window()
dev_open_window(0, 0, 512, 512, 'black', WindowHandle)
dev_set_draw ('margin')
dev_update_window ('off')
dev_set_line_width (2)

*创建条形码模型句柄。
create_bar_code_model ([], [], BarCodeHandle)
*设置要查找的条码的最小宽度参数,也就是黑色和白色矩形 条沿着扫描方向的最小宽度
set_bar_code_param (BarCodeHandle, 'element_size_min', 1.5)
*设置要查找条码的解码过程的中间结果是否保存,1是,0,否。
set_bar_code_param (BarCodeHandle, 'persistence', 1)
*设置最少使用两条扫描线进行计算,结果相同才认为结果正确
set_bar_code_param (BarCodeHandle, 'min_identical_scanlines', 2)
*设置扫码个数(设置为0,则扫描所有条码)
set_bar_code_param (BarCodeHandle, 'stop_after_result_num', 0)

read_image (Image, 'C:/Users/Public/Documents/MVTec/HALCON-18.11-Progress/examples/images/barcode/mixed/barcode_mixed_02.png')
get_image_size (Image, Width, Height)
dev_set_window_extents(0,0,Width, Height)
dev_display (Image)
*在图片中开始查找条码,字符结果保存在DecodedDataStrings,条码区域保存在SymbolRegions
*'auto'自动搜索条码类型
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings)
if(|DecodedDataStrings|)
    CandidatesIds := [0:|DecodedDataStrings|-1]
else
    CandidatesIds := 'all'
endif
for Index := 0 to |DecodedDataStrings|-1 by 1
    *获取条码计算的中间结果:条码区域
    get_bar_code_object(Candidates, BarCodeHandle, CandidatesIds[Index], 'candidate_regions')
    dev_set_color ('green')
    dev_display (Candidates)
    *获取条码计算的中间结果:扫描线
    get_bar_code_object(ValidScanLines, BarCodeHandle, CandidatesIds[Index], 'scanlines_valid')
    dev_set_color ('yellow')
    dev_display (ValidScanLines)
    disp_message (WindowHandle, DecodedDataStrings[Index], 'window', 20*Index, 12, 'black', 'true')
endfor
clear_bar_code_model (BarCodeHandle)

ここに画像の説明を挿入
ここに画像の説明を挿入
2.QRコード

dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
read_image (Image, 'E:/国辰项目/洛丰OCR/图片/Pic_2022_07_15_154015_2.bmp')
rgb1_to_gray (Image, GrayImage)
*创建二维码模型
create_data_code_2d_model ('Data Matrix ECC 200', [], [], DataCodeHandle) 
*利用增强型读码模型
set_data_code_2d_param (DataCodeHandle, 'default_parameters', 'enhanced_recognition')
*读码超时时间ms
set_data_code_2d_param (DataCodeHandle, 'timeout', 200)
*二维码背景之间极性,light_on_dark,dark_on_light,any
set_data_code_2d_param (DataCodeHandle, 'polarity', 'any')
*二维码图像中模块的最小大小,最大大小(以像素为单位)
set_data_code_2d_param(DataCodeHandle, ['module_size_min','module_size_max'], [6,20])
*存在局部反光情况下,扫码算法('low'速度更快,鲁棒性不强, 'high'速度慢,鲁棒性强, 'any')
set_data_code_2d_param(DataCodeHandle, 'contrast_tolerance', 'any')
*二维码图像中模块之间的间隙
set_data_code_2d_param (DataCodeHandle, 'module_gap', 'no')
*描述符号是否被镜像或可能被镜像
set_data_code_2d_param (DataCodeHandle, 'mirrored', 'no')
*控制用于符号检测的候选区域的选择。 将此参数设置为'extensive'会增加生成的候选区域的数量,从而增加检测到代码的可能性。 
*但是,候选者的数量越多,运行时的时间就越长。 如果'candidate_selection'被设置为'default',则会使用更少的候选区域。 在大多数情况下,这个较小的候选集合就足够了。 
set_data_code_2d_param (DataCodeHandle, 'candidate_selection', 'extensive')
*描述模块的大小是否可能变化(在特定范围内)。 根据这个参数,不同的算法被用来计算模块的中心位置。 如果它被设置为'fixed',则会使用一个等距网格。 
*允许可变模块大小('variable'),网格只与查找器模式的交替一侧对齐。
*有了“any”,这两种方法都被一个接一个地测试。 请注意,如果'finder_pattern_tolerance'设置为'high''module_grid'的值会被忽略。 在这种情况下,假设有一个等距网格。 
set_data_code_2d_param (DataCodeHandle, 'module_grid', 'any')

 *读取二维码,读取数量设置11
find_data_code_2d (GrayImage, SymbolXLDs, DataCodeHandle, 'stop_after_result_num', 11, ResultHandles, DecodedDataStrings)
tuple_length (DecodedDataStrings, Length)
area_center_xld (SymbolXLDs, Area, Row, Column, PointOrder)
for Index := 0 to Length-1 by 1
    disp_message (WindowHandle, DecodedDataStrings[Index], 'window', Index*20, 12, 'black', 'true')
endfor

ここに画像の説明を挿入
ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/Douhaoyu/article/details/128581640