使用条形码参数'meas_thresh_abs'的示例程序;该参数可用于在查找我们希望具有高对比度的条形码符号区域时减少误报的数量。为了人工证明这一点,我们试图找到条形码类型的药典,它没有检查字符,因此在噪声中很容易识别。作为“噪音”,我们使用完全不包含任何条形码的图像。通过使用值大于0.0的“meas_thresh_abs”,我们强制条形码阅读器仅使用绝对对比度至少为该值的扫描线部分,从而减少误报的数量。
总代码:
* Create bar code reader model
create_bar_code_model ([], [], BarCodeHandle)
*
* Initialization
*设置变量、pc、窗口为off状态
dev_update_var ('off')
dev_update_pc ('off')
dev_update_window ('off')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
*
* Read and display example images without any visible bar codes
*读取并显示没有任何可见条形码的示例图像
ExampleImages := ['zeiss1','patras','fabrik']
for Index := 0 to |ExampleImages| - 1 by 1
FileName := ExampleImages[Index]
read_image (Image, FileName)
rgb1_to_gray (Image, Image)
*
* Set display defaults
*设置显示默认值
get_image_size (Image, Width, Height)
*设置图像的宽高与窗口保持一致
dev_set_window_extents (-1, -1, Width, Height)
dev_display (Image)
*
* First, disable absolute thresholds by setting the value 0.0
* for the parameter 'meas_thresh_abs'
*首先,通过设置值0.0禁用绝对阈值
*参数'meas_thresh_abs'
MeasThreshAbsValue := 0.0
set_bar_code_param (BarCodeHandle, 'meas_thresh_abs', MeasThreshAbsValue)
*
* The bar code reader finds many (wrong) potential bar codes using
* scanlines that have a low absolute contrast
*条形码阅读器使用绝对对比度低的扫描线
*寻找区域
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'PharmaCode', DecodedDataStrings)
dev_set_color ('red')
dev_display (SymbolRegions)
disp_message (WindowHandle, ['Found ' + |DecodedDataStrings| + ' potential bar codes',' with parameter meas_thresh_abs = ' + MeasThreshAbsValue], 'window', 12, 12, '', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Now, set the bar code reader parameter 'meas_thresh_abs' to a value
* greater than 0.0 to use only parts of a scanline having an absolute
* contrast of at least that value.
*现在,将条形码阅读器参数“meas_thresh_abs”设置为一个值
*大于0.0以仅使用具有绝对至少是这个值的对比度。
MeasThreshAbsValue := 10.0
set_bar_code_param (BarCodeHandle, 'meas_thresh_abs', MeasThreshAbsValue)
*
* Look again for a bar code. Now, significant less scanlines should be found.
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'PharmaCode', DecodedDataStrings)
dev_set_color ('lime green')
dev_display (SymbolRegions)
disp_message (WindowHandle, ['Found ' + |DecodedDataStrings| + ' potential bar codes',' with parameter meas_thresh_abs = ' + MeasThreshAbsValue], 'window', 5 * 12, 12, '', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endfor
*
*把不是很明显的区域去掉,比较明显的提取出来
* Close the bar code reader
clear_bar_code_model (BarCodeHandle)
逐段分析:
*创建模型
create_bar_code_model ([], [], BarCodeHandle)
*初始化
*设置变量、pc、窗口为off状态
dev_update_var ('off')
dev_update_pc ('off')
dev_update_window ('off')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
*读取并显示没有任何可见条形码的示例图像
ExampleImages := ['zeiss1','patras','fabrik']
for Index := 0 to |ExampleImages| - 1 by 1
FileName := ExampleImages[Index]
*读取图片
read_image (Image, FileName)
*灰度化
rgb1_to_gray (Image, Image)
*设置显示默认值
get_image_size (Image, Width, Height)
*设置图像的宽高与窗口保持一致
dev_set_window_extents (-1, -1, Width, Height)
dev_display (Image)
![](https://img-blog.csdnimg.cn/fffe1e35e8944b29b0e749cfed8dadd7.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQm9vbUJpdUJpdQ==,size_20,color_FFFFFF,t_70,g_se,x_16)
*首先,通过设置值0.0禁用绝对阈值
*参数'meas_thresh_abs'
MeasThreshAbsValue := 0.0
set_bar_code_param (BarCodeHandle, 'meas_thresh_abs', MeasThreshAbsValue)
*条形码阅读器使用绝对对比度低的扫描线寻找区域
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'PharmaCode', DecodedDataStrings)
dev_set_color ('red')
*显示寻找到的区域
dev_display (SymbolRegions)
*显示信息
disp_message (WindowHandle, ['Found ' + |DecodedDataStrings| + ' potential bar codes',' with parameter meas_thresh_abs = ' + MeasThreshAbsValue], 'window', 12, 12, '', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
![](https://img-blog.csdnimg.cn/022f3d1fef01468aa2e7c3f3b9182a1f.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQm9vbUJpdUJpdQ==,size_20,color_FFFFFF,t_70,g_se,x_16)
*现在,将条形码阅读器参数“meas_thresh_abs”设置为一个值
*大于0.0以仅使用具有绝对至少是这个值的对比度。
*阈值改为10.0
MeasThreshAbsValue := 10.0
set_bar_code_param (BarCodeHandle, 'meas_thresh_abs', MeasThreshAbsValue)
*再次查找条形码。现在,应该找到显著的扫描线。
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'PharmaCode', DecodedDataStrings)
dev_set_color ('lime green')
*显示寻找到的区域
dev_display (SymbolRegions)
*显示信息
disp_message (WindowHandle, ['Found ' + |DecodedDataStrings| + ' potential bar codes',' with parameter meas_thresh_abs = ' + MeasThreshAbsValue], 'window', 5 * 12, 12, '', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endfor
![](https://img-blog.csdnimg.cn/27e15926856c409b9498041e93a74153.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQm9vbUJpdUJpdQ==,size_20,color_FFFFFF,t_70,g_se,x_16)
*清除句柄
clear_bar_code_model (BarCodeHandle)
![](https://img-blog.csdnimg.cn/22171df2f75148eb903cca4fa8f1e48d.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQm9vbUJpdUJpdQ==,size_20,color_FFFFFF,t_70,g_se,x_16)
![](https://img-blog.csdnimg.cn/2a4ae7240ce448579540839b07cf90eb.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQm9vbUJpdUJpdQ==,size_20,color_FFFFFF,t_70,g_se,x_16)
![](https://img-blog.csdnimg.cn/e0f8d0ff4c194e98bb0d42204c39259e.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQm9vbUJpdUJpdQ==,size_15,color_FFFFFF,t_70,g_se,x_16)
![](https://img-blog.csdnimg.cn/5c82f30aa0fa4f61afcfb1768b49a1ec.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQm9vbUJpdUJpdQ==,size_15,color_FFFFFF,t_70,g_se,x_16)
meas_thresh_abs把不是很明显的区域去掉,比较明显的提取出来
'meas_thresh_abs':
如果扫描线放置在没有或只有非常小的灰度值动态范围的图像区域(例如,在所有灰度值接近255的白色区域),基于“meas_thresh”的边缘检测阈值将被计算得非常小。这通常会导致检测到大量假边缘。”meas_thresh_abs’用于防止此类误判。如果基于“meas_thresh”的阈值小于“meas_thresh_abs”的值,则将后者用作阈值。默认情况下,“meas_thresh_abs”设置为5.0。较大的值可能更适合于高噪声级别的图像。另一方面,在对比度非常弱的无噪图像中,此参数可能会干扰真实边缘的检测,因此可能需要将其减小,甚至通过将其设置为0.0来完全禁用。
典型值:[0.0…10.0]
默认值:5.0