Haicon矫正图像变形

By qq84628151 没有评论

图像矫正前后对比:

*关闭当前显示窗口,清空屏幕
dev_close_window ()
*读取测试图像
read_image (Image_display, 'E:/test_display.jpg')
*将图像转化为灰度图像
rgb1_to_gray (Image_display, GrayImage)
*获取图像的尺寸
get_image_size(Image_display,imageWidth, imageHeight)
*新建显示窗口,适应图像尺寸
dev_open_window (0, 0, imageWidth, imageHeight, 'black', WindowHandle1)
dev_display (GrayImage)
*初始化角点坐标
XCoordCorners := []
YCoordCorners := []
*阈值处理,提取较暗的区域
threshold(GrayImage,DarkRegion,0, 80)
*分离不相连的区域
connection (DarkRegion, ConnectedRegions)
*选择面积最大的暗色区域,即屏幕区域
select_shape_std (ConnectedRegions, displayRegion, 'max_area', 70)
*裁剪屏幕区域
reduce_domain (GrayImage, displayRegion, displayImage)
*创建边缘轮廓
gen_contour_region_xld (displayRegion, Contours, 'border')
*将轮廓分割为边
segment_contours_xld (Contours, ContoursSplit, 'lines', 5, 4, 2)
*获取边的数量
count_obj (ContoursSplit, Number)
*存储每条边的起点位置
for index:=1 to Number by 1
   select_obj(ContoursSplit, ObjectCurrent, index)
   *拟合每条边
   fit_line_contour_xld (ObjectCurrent, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
   *存储每条边的顶点x坐标
   tuple_concat (XCoordCorners, RowBegin, XCoordCorners)
   *存储每条边的顶点y坐标
   tuple_concat (YCoordCorners, ColBegin, YCoordCorners)
endfor

* 投影变换给四个特征点与校正后的坐标建立关联
XOff:= 100
YOff:= 100*imageHeight/imageWidth
hom_vector_to_proj_hom_mat2d (XCoordCorners, YCoordCorners, [1,1,1,1], [YOff,YOff,imageHeight-YOff,imageHeight-YOff], [XOff,imageWidth-XOff,imageWidth-XOff,XOff], [1,1,1,1], 'normalized_dlt', HomMat2D)
*投影变换
projective_trans_image (Image_display, Image_rectified, HomMat2D, 'bilinear', 'false', 'false')
* 显示校正结果
dev_display (Image_rectified)

二维码矫正前后对比:

dev_close_window()
read_image(Image, 'E:/test1111.jpg')
get_image_size(Image, Width, Height)
dev_open_window(0,0, Width / 2, Height / 2, 'black', WindowHandle)
rgb1_to_gray(Image, ImageGray)
dev_display(ImageGray)
create_data_code_2d_model('QR Code', [], [], DataCodeHandle)
find_data_code_2d(ImageGray, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
get_contour_xld(SymbolXLDs, Rows, Cols)
dev_display(SymbolXLDs)
Rows := remove(Rows, 4)
Cols := remove(Cols, 4)
XOff:= 100
YOff:= 100*Height/Width
hom_vector_to_proj_hom_mat2d(Rows, Cols, [1, 1, 1, 1], [YOff,YOff,Height-YOff,Height-YOff], [XOff,Width-XOff,Width-XOff,XOff], [1, 1, 1, 1], 'normalized_dlt', HomMat2D)
projective_trans_image(ImageGray, Image_rectified, HomMat2D, 'bilinear', 'false', 'true')