该程序演示了如何通过灰度值形态学最小化模块之间的大间隙,以便找到并解码二维数据代码符号
总代码:
*更新状态设为off
dev_update_off ()
dev_close_window ()
*
* Get the image and display it
*获取图像并显示
*读取图片
read_image (Image, 'datacode/ecc200/ecc200_to_preprocess_003')
*打开自适应图片的窗口
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
*设置一些变量
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_line_width (3)
dev_set_color ('green')
*显示图片
dev_display (Image)
Message := 'This program demonstrates how to'
Message[1] := 'preprocess data code symbols with'
Message[2] := 'large gaps between the modules using'
Message[3] := 'gray value morphology.'
*显示信息--该程序演示了如何使用灰度形态学对模块之间存在较大间隙的数据代码符号进行预处理
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Create the data code model and adapt the parameters to the
* biggest allowed module gap ’big’ before reading the code
*创建数据代码模型,并在读取代码之前将参数调整到允许的最大模块间隙“大”
*模块的最小间隙/最大间隙
*这个设置是让最大间隙比较大
create_data_code_2d_model ('Data Matrix ECC 200', ['module_gap_min','module_gap_max'], ['no','big'], DataCodeHandle)
*寻找二维码
find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
*
* Now preprocess and then search for the data code and read it
*现在进行预处理,然后搜索数据代码并读取
if (|ResultHandles| == 0)
*显示图片
dev_display (Image)
Message := 'Search was carried out with adapted'
Message[1] := 'parameters in the data code model,'
Message[2] := 'but still no data code could be found!'
*显示信息--使用数据代码模型中的自适应参数进行搜索,但仍然找不到数据代码!
disp_message (WindowHandle, Message, 'window', 12, 12, 'red', 'true')
Message := 'Now adapt the image instead of the model.'
Message[1] := 'Therefor preprocess the image using'
Message[2] := 'gray-value erosion and then search again'
Message[3] := 'for the data code symbol.'
*显示信息--现在调整图像而不是模型。因此,对图像进行灰度腐蚀预处理,然后再搜索数据编码符号。
disp_message (WindowHandle, Message, 'window', 100, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Preprossesing with gray value erosion
*灰度侵蚀预渗透,确定选定遮罩内的最小灰度值。
*每个图像点计算形状MaskShape、垂直大小MaskHeight和水平大小MaskWidth遮罩内输入图像的最小灰度值。
gray_erosion_shape (Image, ImageMin, 15, 15, 'rectangle')
*寻找二维码
find_data_code_2d (ImageMin, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
dev_display (ImageMin)
* Display message about the preprocessing
*显示有关预处理的消息
Message := 'Data code found after adapting the image'
*显示信息--调整图像后发现数据代码
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
*显示信息--预处理:灰度侵蚀
disp_message (WindowHandle, 'Preprocessing: Gray value erosion', 'window', 60, 12, 'black', 'true')
endif
*
* Display the decoded data string
*显示信息--显示解码后的数据字符串
disp_message (WindowHandle, 'Decoded string: ' + DecodedDataStrings, 'window', 80, 12, 'black', 'true')
dev_display (SymbolXLDs)
*
*释放二维码阅读器分配的内存
clear_data_code_2d_model (DataCodeHandle)
逐段分析:
*更新状态设为off
dev_update_off ()
dev_close_window ()
*获取图像并显示
*读取图片
read_image (Image, 'datacode/ecc200/ecc200_to_preprocess_003')
*打开自适应图片的窗口
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
*设置一些变量
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_line_width (3)
dev_set_color ('green')
*显示图片
dev_display (Image)

Message := 'This program demonstrates how to'
Message[1] := 'preprocess data code symbols with'
Message[2] := 'large gaps between the modules using'
Message[3] := 'gray value morphology.'
*显示信息--该程序演示了如何使用灰度形态学对模块之间存在较大间隙的数据代码符号进行预处理
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()

*创建数据代码模型,并在读取代码之前将参数调整到允许的最大模块间隙“大”
*模块的最小间隙/最大间隙
*这个设置是让最大间隙比较大
create_data_code_2d_model ('Data Matrix ECC 200', ['module_gap_min','module_gap_max'], ['no','big'], DataCodeHandle)
*寻找二维码
find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
*现在进行预处理,然后搜索数据代码并读取
*如果没有找到二维码
if (|ResultHandles| == 0)
*显示图片
dev_display (Image)
Message := 'Search was carried out with adapted'
Message[1] := 'parameters in the data code model,'
Message[2] := 'but still no data code could be found!'
*显示信息--使用数据代码模型中的自适应参数进行搜索,但仍然找不到数据代码!
disp_message (WindowHandle, Message, 'window', 12, 12, 'red', 'true')
Message := 'Now adapt the image instead of the model.'
Message[1] := 'Therefor preprocess the image using'
Message[2] := 'gray-value erosion and then search again'
Message[3] := 'for the data code symbol.'
*显示信息--现在调整图像而不是模型。因此,对图像进行灰度腐蚀预处理,然后再搜索数据编码符号。
disp_message (WindowHandle, Message, 'window', 100, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()

*灰度侵蚀预渗透,确定选定遮罩内的最小灰度值。
*每个图像点计算形状MaskShape、垂直大小MaskHeight和水平大小MaskWidth遮罩内输入图像的最小灰度值。
gray_erosion_shape (Image, ImageMin, 15, 15, 'rectangle')

*寻找二维码
find_data_code_2d (ImageMin, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)

*显示有关预处理的消息
Message := 'Data code found after adapting the image'
*显示信息--调整图像后发现数据代码
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
*显示信息--预处理:灰度侵蚀
disp_message (WindowHandle, 'Preprocessing: Gray value erosion', 'window', 60, 12, 'black', 'true')
endif
*显示信息--显示解码后的数据字符串
disp_message (WindowHandle, 'Decoded string: ' + DecodedDataStrings, 'window', 80, 12, 'black', 'true')
dev_display (SymbolXLDs)
*释放二维码阅读器分配的内存
clear_data_code_2d_model (DataCodeHandle)

主要算子分析:
gray_erosion_shape(Image : ImageMin : MaskHeight, MaskWidth, MaskShape : )
功能:确定选定遮罩内的最小灰度值。每个图像点计算形状MaskShape、垂直大小MaskHeight和水平大小MaskWidth遮罩内输入图像的最小灰度值。
Image:要计算最小灰度值的图像。
ImageMin:包含最小灰度值的图像。
MaskHeight:过滤器遮罩的高度。
MaskWidth:过滤器遮罩的宽度。
MaskShape: 过滤器遮罩的形状。