本文主要是介绍基于Halcon学习的二维码识别【四】2d_data_codes_minimize_noise.hdev,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
这个程序演示了如何预处理带有间隙、不同颜色的模块和扭曲的安静区的符号
总代码:
*更新状态设为off
dev_update_off ()
dev_close_window ()
* Get the image and display it
*获取图像并显示
*读取图片
read_image (Image, 'datacode/ecc200/ecc200_to_preprocess_004')
*打开自适应图片的窗口
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)
*
* Display short description
*显示简短描述Message := 'This program demonstrates the'
Message[1] := 'preproccessing of a data code symbol'
Message[2] := 'with gaps, modules of different color'
Message[3] := 'and a distorted quiet zone.'
*显示信息--这个程序演示了一个数据代码符号的预处理过程,其中包含间隙、不同颜色的模块和扭曲的安静区
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Step 1: Create a 2d data code model
* -------------------------------------------------------
* Create a 2d data code model of the 2d data code class
* 'Data Matrix ECC 200' with 'default_parameters' set to
* 'enhanced_recognition'.
*步骤1:创建二维数据代码模型
*创建二维数据代码类的二维数据代码模型
*“默认参数”设置为'enhanced_recognition'的“数据矩阵ECC 200”
create_data_code_2d_model ('Data Matrix ECC 200', 'default_parameters', 'enhanced_recognition', DataCodeHandle)
*
* Set the parameters to the biggest allowed module gap
*将参数设置为允许的最大模块间隙
*最小模块间隙--最大模块间隙
set_data_code_2d_param (DataCodeHandle, ['module_gap_min','module_gap_max'], ['no','big'])
*
* Try to find and decode the data codes
*试着找到并解码数据代码
*寻找二维码
find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
*
* Preprocessing
* -----------------------------------------------
* If no data code was found preprocess the image,
* first with gray value morphology and then with
* median filtering, and search for the symbol again
*预处理
*如果没有找到数据代码,请对图像进行预处理,
*首先使用灰度形态学,然后使用中值滤波,然后再次搜索符号*如果没有找到二维码
if (|ResultHandles| == 0)* * Preprocess with gray value morphology*灰度形态学预处理*增加了对比度-让背景更加的一致gray_opening_shape (Image, ImageOpening, 7, 7, 'octagon')* * Find and decode the data codes*找到并解码数据代码*寻找二维码find_data_code_2d (ImageOpening, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)* * Display result*显示结果dev_display (ImageOpening)dev_display (SymbolXLDs)*显示信息--预处理:灰度值开运算disp_message (WindowHandle, 'Preprocessing: Gray value opening', 'window', 12, 12, 'black', 'true')*显示信息--结果disp_message (WindowHandle, 'Decoded string: ' + DecodedDataStrings, 'window', 40, 12, 'black', 'true')disp_continue_message (WindowHandle, 'black', 'true')stop ()* * Preprocess with median filtering*中值滤波预处理median_image (Image, ImageMedian, 'circle', 3, 'continued')* * Find and decode the data codes*找到并解码数据代码*寻找二维码find_data_code_2d (ImageMedian, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)* * Display resultdev_display (ImageMedian)dev_display (SymbolXLDs)*显示信息--预处理:中值滤波'disp_message (WindowHandle, 'Preprocessing: Median filtering', 'window', 12, 12, 'black', 'true')*显示信息--结果disp_message (WindowHandle, 'Decoded string: ' + DecodedDataStrings, 'window', 40, 12, 'black', 'true')stop ()
else* * Display the results if no preprocessing* was necessary*如果不需要预处理,则显示结果dev_display (Image)dev_display (SymbolXLDs)*显示信息--解码成功无需预处理'disp_message (WindowHandle, 'Decoding successful\nNo preprocessing necessary', 'window', 12, 12, 'black', 'true')disp_message (WindowHandle, 'Decoded string: ' + DecodedDataStrings, 'window', 60, 12, 'black', 'true')
endif
*
* Clear the data code model
clear_data_code_2d_model (DataCodeHandle)
逐段分析:
*更新状态设为off
dev_update_off ()
dev_close_window ()*获取图像并显示
*读取图片
read_image (Image, 'datacode/ecc200/ecc200_to_preprocess_004')*打开自适应图片的窗口
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 the'
Message[1] := 'preproccessing of a data code symbol'
Message[2] := 'with gaps, modules of different color'
Message[3] := 'and a distorted quiet zone.'*显示信息--这个程序演示了一个数据代码符号的预处理过程,其中包含间隙、不同颜色的模块和扭曲的安静区
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*步骤1:创建二维数据代码模型
*创建二维数据代码类的二维数据代码模型
*“默认参数”设置为'enhanced_recognition'的“数据矩阵ECC 200”
create_data_code_2d_model ('Data Matrix ECC 200', 'default_parameters', 'enhanced_recognition', DataCodeHandle)*将参数设置为允许的最大模块间隙
*最小模块间隙--最大模块间隙
set_data_code_2d_param (DataCodeHandle, ['module_gap_min','module_gap_max'], ['no','big'])*试着找到并解码数据代码
*寻找二维码
find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
*预处理
*如果没有找到数据代码,请对图像进行预处理,
*首先使用灰度形态学,然后使用中值滤波,然后再次搜索符号*如果没有找到二维码
if (|ResultHandles| == 0)*灰度形态学预处理*增加了对比度-让背景更加的一致gray_opening_shape (Image, ImageOpening, 7, 7, 'octagon')
*找到并解码数据代码*寻找二维码find_data_code_2d (ImageMedian, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)dev_display (ImageMedian)dev_display (SymbolXLDs)*显示信息--预处理:中值滤波'disp_message (WindowHandle, 'Preprocessing: Median filtering', 'window', 12, 12, 'black', 'true')*显示信息--结果disp_message (WindowHandle, 'Decoded string: ' + DecodedDataStrings, 'window', 40, 12, 'black', 'true')stop ()
*中值滤波预处理median_image (Image, ImageMedian, 'circle', 3, 'continued')
*找到并解码数据代码*寻找二维码find_data_code_2d (ImageMedian, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)dev_display (ImageMedian)dev_display (SymbolXLDs)*显示信息--预处理:中值滤波'disp_message (WindowHandle, 'Preprocessing: Median filtering', 'window', 12, 12, 'black', 'true')*显示信息--结果disp_message (WindowHandle, 'Decoded string: ' + DecodedDataStrings, 'window', 40, 12, 'black', 'true')stop ()else*如果不需要预处理,则显示结果dev_display (Image)dev_display (SymbolXLDs)*显示信息--解码成功无需预处理'disp_message (WindowHandle, 'Decoding successful\nNo preprocessing necessary', 'window', 12, 12, 'black', 'true')disp_message (WindowHandle, 'Decoded string: ' + DecodedDataStrings, 'window', 60, 12, 'black', 'true')
endif
*释放二维码阅读器分配的内存
clear_data_code_2d_model (DataCodeHandle)
主要算子分析:
gray_opening_shape(Image : ImageOpening : MaskHeight, MaskWidth, MaskShape : )
功能:使用选定遮罩执行灰度值开运算
Image:要计算最小灰度值的图像。
ImageMin:包含最小灰度值的图像。
MaskHeight:过滤器遮罩的高度。
MaskWidth:过滤器遮罩的宽度。
MaskShape: 过滤器遮罩的形状。
这篇关于基于Halcon学习的二维码识别【四】2d_data_codes_minimize_noise.hdev的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!