基于Halcon学习的二维码识别【八】ecc200_contrast_tolerance.hdev

此示例演示了ECC200读卡器的参数“对比度公差”参数的影响

如果'contrast_tolerance'”设置为“高”,ECC200读卡器对符号内的局部对比度变化更宽容。这是通过内部预处理实现的。如果'contrast_tolerance'设置为“低”,则省略此预处理步骤。如果'contrast_tolerance'设置为“任意”,则读取器会尝试两种模式。请注意,“对比度公差”也包括在ECC200读卡器的训练模式中。


总代码:

*更新状态设为off
dev_update_off ()
*关闭窗口
dev_close_window ()
* 
* Initialize image path and window size
*初始化图像路径和窗口大小
*遍历图片
list_image_files ('datacode/ecc200', 'default', [], ImageFiles)
*选择与正则表达式匹配的tuple元素。例如,用于过滤使用操作员列表_文件获得的文件列表。
*'contrast_variations'--“对比变化”
tuple_regexp_select (ImageFiles, 'contrast_variations', ImageFiles)
*读取图片
read_image (Image, ImageFiles[0])
*打开自适应图片的窗口
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_color ('green')
dev_set_line_width (3)
* 
* Display short description
*显示简短描述
Message := 'This example program demonstrates how the parameter'
Message[1] := '\'contrast_tolerance\' influences the search with a'
Message[2] := 'ECC200 reader for 2d data code symbols with local'
Message[3] := 'contrast variations.'
*显示信息--该示例程序演示了参数“对比度公差”如何影响ECC200读取器对具有局部对比度变化的二维数据代码符号的搜索。
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Create ECC200 data code model with 'contrast_tolerance' set to 'low'
*创建“对比度公差”设置为“低”的ECC200数据代码模型
create_data_code_2d_model ('Data Matrix ECC 200', 'default_parameters', 'enhanced_recognition', DataCodeHandleLow)
*设置参数为low
set_data_code_2d_param (DataCodeHandleLow, 'contrast_tolerance', 'low')
* 
* Create ECC200 data code model with 'contrast_tolerance' set to 'high'
*创建“对比度公差”设置为“高”的ECC200数据代码模型
create_data_code_2d_model ('Data Matrix ECC 200', 'default_parameters', 'enhanced_recognition', DataCodeHandleHigh)
*设置参数为low
set_data_code_2d_param (DataCodeHandleHigh, 'contrast_tolerance', 'high')
* 
*对4张图片开始循环
for Index := 0 to 4 by 1
    *读取图片
    read_image (Image, ImageFiles[Index])
    Loops := 2
    * Try to find the data code symbol with 'contrast_tolerance' set to 'low'
    *尝试查找“对比度公差”设置为“低”的数据代码符号
    *计算开始时间
    count_seconds (T1)
    for Loop := 1 to Loops by 1
        *寻找二维码
        find_data_code_2d (Image, SymbolXLDs, DataCodeHandleLow, [], [], ResultHandles, DecodedDataStrings)
    endfor
    *计算结束时间
    count_seconds (T2)
    FoundLow := |DecodedDataStrings|
    TimeLow := 1000 * (T2 - T1) / Loops
    * 
    * Try to find the data code symbol with 'contrast_tolerance' set to 'high'
    *尝试查找“对比度公差”设置为“高”的数据代码符号
    *计算开始时间
    count_seconds (T1)
    for Loop := 1 to Loops by 1
        find_data_code_2d (Image, SymbolXLDs, DataCodeHandleHigh, [], [], ResultHandles, DecodedDataStrings)
    endfor
    *计算结束时间
    count_seconds (T2)
    FoundHigh := |DecodedDataStrings|
    TimeHigh := 1000 * (T2 - T1) / Loops
    * 
    * Create message about the search
    *创建有关搜索的消息
    Color := gen_tuple_const(4,'black')
    Message := 'Runtime:'
    Message[1] := '\'contrast_tolerance\' = \'low\': ' + TimeLow$'8.2f' + ' ms'
    if (FoundLow == 0)
        Message[1] := Message[1] + '  (no symbol found)'
        Color[1] := 'red'
    endif
    Message[2] := '\'contrast_tolerance\' = \'high\':' + TimeHigh$'8.2f' + ' ms'
    if (FoundHigh == 0)
        Message[2] := Message[2] + '  (no symbol found)'
        Color[2] := 'red'
    endif
    * 
    * Display the data code symbol and information about runtime
    *显示数据代码符号和有关运行时的信息
    dev_display (Image)
    dev_display (SymbolXLDs)
    disp_message (WindowHandle, 'Image ' + (Index + 1) + ' of 5', 'window', 12, 12, 'black', 'true')
    disp_message (WindowHandle, Message, 'window', 40, 12, Color, 'true')
    * 
    * Display continue message
    *显示继续消息
    if (Index < 5)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
* 
* Clear the 2d data code models
*清除二维数据代码模型
clear_data_code_2d_model (DataCodeHandleLow)
clear_data_code_2d_model (DataCodeHandleHigh)

逐段分析:

*更新状态设为off
dev_update_off ()

*关闭窗口
dev_close_window ()

*初始化图像路径和窗口大小
*遍历图片
list_image_files ('datacode/ecc200', 'default', [], ImageFiles)

*选择与正则表达式匹配的tuple元素。例如,用于过滤使用操作员列表_文件获得的文件列表。
*'contrast_variations'--“对比变化”
tuple_regexp_select (ImageFiles, 'contrast_variations', ImageFiles)

*读取图片
read_image (Image, ImageFiles[0])

*打开自适应图片的窗口
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_color ('green')
dev_set_line_width (3)

*显示简短描述
Message := 'This example program demonstrates how the parameter'
Message[1] := '\'contrast_tolerance\' influences the search with a'
Message[2] := 'ECC200 reader for 2d data code symbols with local'
Message[3] := 'contrast variations.'

*显示信息--该示例程序演示了参数“对比度公差”如何影响ECC200读取器
对具有局部对比度变化的二维数据代码符号的搜索。
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()

*创建“对比度公差”设置为“低”的ECC200数据代码模型
create_data_code_2d_model ('Data Matrix ECC 200', 'default_parameters', 'enhanced_recognition', DataCodeHandleLow)

*设置参数为low
set_data_code_2d_param (DataCodeHandleLow, 'contrast_tolerance', 'low')

*创建“对比度公差”设置为“高”的ECC200数据代码模型
create_data_code_2d_model ('Data Matrix ECC 200', 'default_parameters', 'enhanced_recognition', DataCodeHandleHigh)

*设置参数为low
set_data_code_2d_param (DataCodeHandleHigh, 'contrast_tolerance', 'high')

*对4张图片开始循环
for Index := 0 to 4 by 1
    *读取图片
    read_image (Image, ImageFiles[Index])

    *定义寻找二维码的次数
    Loops := 2

    *尝试查找“对比度公差”设置为“低”的数据代码符号
    *计算开始时间
    count_seconds (T1)
    for Loop := 1 to Loops by 1
        *寻找二维码
        find_data_code_2d (Image, SymbolXLDs, DataCodeHandleLow, [], [], ResultHandles, DecodedDataStrings)
    endfor

    *计算结束时间
    count_seconds (T2)
    FoundLow := |DecodedDataStrings|
    TimeLow := 1000 * (T2 - T1) / Loops

    *尝试查找“对比度公差”设置为“高”的数据代码符号
    *计算开始时间
    count_seconds (T1)
    for Loop := 1 to Loops by 1
        *寻找二维码
        find_data_code_2d (Image, SymbolXLDs, DataCodeHandleHigh, [], [], ResultHandles, DecodedDataStrings)
    endfor

    *计算结束时间
    count_seconds (T2)

      *为变量分配新值。
    Color := gen_tuple_const(4,'black')
    Message := 'Runtime:'
    Message[1] := '\'contrast_tolerance\' = \'low\': ' + TimeLow$'8.2f' + ' ms'
    if (FoundLow == 0)
        Message[1] := Message[1] + '  (no symbol found)'
        Color[1] := 'red'
    endif
    Message[2] := '\'contrast_tolerance\' = \'high\':' + TimeHigh$'8.2f' + ' ms'
   
    if (FoundHigh == 0)
        Message[2] := Message[2] + '  (no symbol found)'
        Color[2] := 'red'
    endif
    
    *显示数据代码符号和有关运行时的信息
    dev_display (Image)
    dev_display (SymbolXLDs)
    disp_message (WindowHandle, 'Image ' + (Index + 1) + ' of 5', 'window', 12, 12, 'black', 'true')
    disp_message (WindowHandle, Message, 'window', 40, 12, Color, 'true')

    *显示继续消息
    if (Index < 5)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor

*清除二维数据代码模型
clear_data_code_2d_model (DataCodeHandleLow)
clear_data_code_2d_model (DataCodeHandleHigh)

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在C#中使用Halcon实现二维码识别可以通过以下步骤进行: 1. 首先,确保你已经安装了Halcon的开发环境,并且在C#项目中引入了Halcon的相关库。 2. 创建一个Halcon图像对象,将待识别图像加载到该对象中。 3. 使用Halcon提供的二维码识别函数对图像进行处理并得到识别结果。例如,可以使用`find_bar_code`函数来查找二维码,并使用`decode_bar_code_2d`函数对二维码进行解码。 4. 获取识别结果并进行后续处理。你可以将识别到的二维码信息显示在界面上或者进行其他操作,如数据存储、网络传输等。 以下是一个简单的示例代码,演示了如何在C#中使用Halcon实现二维码识别: ```csharp using HalconDotNet; class Program { static void Main(string[] args) { // 加载Halcon引擎 HOperatorSet.SetSystem("border_shape_models", "true"); // 创建Halcon图像对象 HObject image = new HObject(); // 从文件中加载待识别图像 HOperatorSet.ReadImage(out image, "path_to_your_image"); // 定义变量用于存储识别结果 HTuple decodedDataStrings = new HTuple(); // 进行二维码识别 HOperatorSet.FindBarCode(image, out image, new HTuple("QR_CODE"), out decodedDataStrings); // 打印识别结果 Console.WriteLine("QR Code: " + decodedDataStrings.ToString()); // 释放资源 image.Dispose(); // 关闭Halcon引擎 HOperatorSet.CloseAll(); } } ``` 请注意,以上代码只是一个简单的示例,实际应用中可能需要根据具体情况进行适当的参数调整和异常处理。另外,你需要替换代码中的图像路径为你自己的图像路径。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值