这个程序演示了如何通过校正预处理来读取倾斜的二维码
总代码:
*更新状态设为off
dev_update_off ()
dev_close_window ()
* Get the image and display it
*获取图像并显示它
read_image (Image_slanted, 'datacode/ecc200/ecc200_to_preprocess_001')
*打开自适应图片的窗口
dev_open_window_fit_image (Image_slanted, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_color ('green')
dev_set_line_width (3)
Message := 'This program demonstrates how to preprocess'
Message[1] := 'a slanted 2d data code with rectification'
Message[2] := 'before reading the data code symbol.'
*显示信息--'此程序演示如何在读取数据代码符号之前对倾斜的二维数据代码进行预处理,并进行校正。
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Initialize coordinates
*初始化坐标
XCoordCorners := [130,225,290,63]
YCoordCorners := [101,96,289,269]
*
* Display the slanted image and the corners of the symbol
*显示倾斜图像和符号的箭头
gen_cross_contour_xld (Crosses, XCoordCorners, YCoordCorners, 6, 0.785398)
*显示图片
dev_display (Image_slanted)
*显示箭头
dev_display (Crosses)
*显示信息--倾斜图像
disp_message (WindowHandle, 'Slanted image', 'window', 12, 12, 'black', 'true')
Message := 'The marked corners are used to generate a'
Message[1] := 'homogeneous transformation matrix which'
Message[2] := 'defines the projective transformation for'
Message[3] := 'the rectification of the symbol.'
*显示信息--标记的角点用于生成“齐次变换矩阵”,该矩阵定义了符号矫正的投影变换。
disp_message (WindowHandle, Message, 'window', 380, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* First generate a transformation matrix using the given points
* of the corners of the data code symbol and the corresponding points
* of a quare.
*首先,使用数据代码符号角点的给定点和正方形的对应点生成变换矩阵。
*使用给定的点对应关系计算齐次变换矩阵。
hom_vector_to_proj_hom_mat2d (XCoordCorners, YCoordCorners, [1,1,1,1], [70,270,270,70], [100,100,300,300], [1,1,1,1], 'normalized_dlt', HomMat2D)
*
* Now rectifiy the slanted image by applying the projective transformation
*现在应用投影变换校正倾斜图像
*对图像应用投影变换
projective_trans_image (Image_slanted, Image_rectified, HomMat2D, 'bilinear', 'false', 'false')
*
* Create the data code model and search
* for the data code in the rectified image
*创建数据代码模型,并在校正后的图像中搜索数据代码
create_data_code_2d_model ('Data Matrix ECC 200', [], [], DataCodeHandle)
*寻找二维码
find_data_code_2d (Image_rectified, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
*
* Display result
*显示结果
*倾斜图像
dev_display (Image_slanted)
*矫正图像
dev_display (Image_rectified)
dev_display (SymbolXLDs)
*显示信息--解码成功
disp_message (WindowHandle, 'Decoding successful ', 'window', 12, 12, 'black', 'true')
set_display_font (WindowHandle, 12, 'mono', 'true', 'false')
disp_message (WindowHandle, DecodedDataStrings, 'window', 350, 70, 'forest green', 'true')
*
* Clear the data code model
*清除数据代码模型
clear_data_code_2d_model (DataCodeHandle)
逐段分析:
dev_update_off ()
dev_close_window ()
*获取图像并显示它
read_image (Image_slanted, 'datacode/ecc200/ecc200_to_preprocess_001')
*打开自适应图片的窗口
dev_open_window_fit_image (Image_slanted, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_color ('green')
dev_set_line_width (3)
Message := 'This program demonstrates how to preprocess'
Message[1] := 'a slanted 2d data code with rectification'
Message[2] := 'before reading the data code symbol.'
*显示信息--'此程序演示如何在读取数据代码符号之前对倾斜的二维数据代码进行预处理,并进行校正
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
![](https://i-blog.csdnimg.cn/blog_migrate/46579cdbabb33cae56022dca3ec24ca5.png)
*初始化坐标
XCoordCorners := [130,225,290,63]
YCoordCorners := [101,96,289,269]
*显示倾斜图像和符号的箭头
gen_cross_contour_xld (Crosses, XCoordCorners, YCoordCorners, 6, 0.785398)
![](https://i-blog.csdnimg.cn/blog_migrate/f857751851d1fe059bb9ffbe0236c8da.png)
*显示图片
dev_display (Image_slanted)
*显示箭头
dev_display (Crosses)
*显示信息--倾斜图像
disp_message (WindowHandle, 'Slanted image', 'window', 12, 12, 'black', 'true')
![](https://i-blog.csdnimg.cn/blog_migrate/8ed8ff925f275be215f261c077008bdc.png)
Message := 'The marked corners are used to generate a'
Message[1] := 'homogeneous transformation matrix which'
Message[2] := 'defines the projective transformation for'
Message[3] := 'the rectification of the symbol.'
*显示信息--标记的角点用于生成“齐次变换矩阵”,该矩阵定义了符号矫正的投影变换。
disp_message (WindowHandle, Message, 'window', 380, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
![](https://i-blog.csdnimg.cn/blog_migrate/c07ee91abaf797beb5464c5c24d6d119.png)
*首先,使用数据代码符号角点的给定点和正方形的对应点生成变换矩阵。
*使用给定的点对应关系计算齐次变换矩阵。
hom_vector_to_proj_hom_mat2d (XCoordCorners, YCoordCorners, [1,1,1,1], [70,270,270,70], [100,100,300,300], [1,1,1,1], 'normalized_dlt', HomMat2D)
*现在应用投影变换校正倾斜图像
*对图像应用投影变换
projective_trans_image (Image_slanted, Image_rectified, HomMat2D, 'bilinear', 'false', 'false')
![](https://i-blog.csdnimg.cn/blog_migrate/5ebd48a8dbb12b7cdbb1c379b1a6301f.png)
*创建数据代码模型,并在校正后的图像中搜索数据代码
create_data_code_2d_model ('Data Matrix ECC 200', [], [], DataCodeHandle)
*寻找二维码
find_data_code_2d (Image_rectified, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
*显示结果
*倾斜图像
dev_display (Image_slanted)
*矫正图像
dev_display (Image_rectified)
dev_display (SymbolXLDs)
*显示信息--解码成功
disp_message (WindowHandle, 'Decoding successful ', 'window', 12, 12, 'black', 'true')
set_display_font (WindowHandle, 12, 'mono', 'true', 'false')
disp_message (WindowHandle, DecodedDataStrings, 'window', 350, 70, 'forest green', 'true')
*清除数据代码模型
clear_data_code_2d_model (DataCodeHandle)
![](https://i-blog.csdnimg.cn/blog_migrate/eceb201a917b88bf2cc705e1d19f7545.png)
主要算子分析:
hom_vector_to_proj_hom_mat2d( : : Px, Py, Pw, Qx, Qy, Qw, Method : HomMat2D)
功能:使用给定的点对应关系计算齐次变换矩阵,确定齐次射影变换矩阵HomMat2D,该矩阵通过至少4个点的对应关系最佳地满足以下等式
Px:输入点1(x坐标)
Py:输入点1(y坐标)
Pw:输入点1(w坐标)
Qx:输入点2(x坐标)
Qy:输入点2(y坐标)
Qw:输入点2(w坐标)
Method :估计算法
HomMat2D:齐次投影变换矩阵
projective_trans_image(Image : TransImage : HomMat2D, Interpolation, AdaptImageSize, TransformDomain : )
功能:对图像应用投影变换,将齐次变换矩阵HomMat2D确定的投影变换(单应)应用于输入图像,并将结果存储到输出图像TransImage中
Image :输入图像
TransImage :输出图像
HomMat2D:齐次投影变换矩阵
Interpolation:插值变换法
AdaptImageSize:自动调整输出图像的大小
TransformDomain :输入图像的域也应该被转换吗