1.几何变换

  定义:利用一套控制点和变换方程,将数字地图或图像从一种坐标系转换成另一种坐标系的过程

  操作对象:矢量(数字地图)——重投影过程     栅格(图像)——重采样过程

  转换精度的评价RMS:均方根误差——度量控制点从真实位置到估算位置之间的偏移

2.各种仿射矩阵

  

read_image (Image, 'printer_chip/printer_chip_01')
get_image_size (Image, Width, Height)

*生成标准矩阵
hom_mat2d_identity (HomMat2DIdentity)

*平移
hom_mat2d_translate (HomMat2DIdentity, Height/2, Width/2,  HomMat2DTranslate)

*旋转  hom_mat2d_rotate旋转默认不会改变图像大小,但当仿射图像时最后一个参数为true,右侧和下方的超出图像的区域会被裁减掉,此时图像大小会变化
hom_mat2d_rotate (HomMat2DIdentity, rad(90), Height/2, Width/2, HomMat2DRotate)
*rotate_image围绕中心旋转,会改变图像大小
rotate_image (Image, ImageRotate, 90, 'constant')
*镜像
mirror_image (ImageRotate, ImageMirror, 'row')

*缩放
hom_mat2d_scale (HomMat2DIdentity, 0.5, 0.5, 0, 0, HomMat2DScale)
*图像仿射变换  最后一个为true,会对图像进行裁剪,右侧和下方的超出图像的区域会被裁减掉,此时图像大小会变化
affine_trans_image (Image, ImageAffineTrans, HomMat2DScale, 'constant', 'true')
*zoom_image_factor是以0,0位缩放起点,会改变图像大小
zoom_image_factor (Image, ImageZoomed, 0.5, 0.5, 'constant')
*上述ImageZoomed图像和ImageAffineTrans完全一样

*斜切
hom_mat2d_slant (HomMat2DIdentity, rad(45), 'x', Height/2, Width/2, HomMat2DSlant)
halcon示例

3.九点标定

  由来:相机和机器人原点不一致(平移)、安装角度不一致(旋转)、图像坐标到世界坐标的映射(缩放)、机器人的轴不可能一定是90度(斜切)

算子 输入 输出 俗称
vector_to_hom_mat2d( : : Px, Py, Qx, Qy : HomMat2D) 输入为数组,PxPy为图像坐标(不在一条线上的安个点),QxQy为机器人坐标 包括平移、旋转、缩放、斜切, 九点标定(多是图像坐标到机器人师姐坐标的映射)
vector_angle_to_rigid( : : Row1, Column1, Angle1, Row2, Column2, Angle2 : HomMat2D) 输入为一个点加角度,输出为一个点加角度 包括平移、旋转 仿射变换(都是在图像坐标系内的刚性变换)

4.示例

       

dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
read_image (Image, 'cali/grid_space.cal.k.003')
threshold (Image, Region, 0, 100)
connection (Region, ConnectedRegions)
*筛选圆点
select_shape (ConnectedRegions, SelectedRegions, 'circularity', 'and', 0.5139, 1)
select_shape (SelectedRegions, SelectedRegions1, 'area', 'and', 150, 99999)

*把圆点搞正
union1 (SelectedRegions1, RegionUnion)
smallest_rectangle2 (RegionUnion, Row, Column, Phi, Length1, Length2)
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
*通过点角度,对应关系得到变换矩阵
vector_angle_to_rigid (Row, Column, Phi, Row, Column, 0, HomMat2D)
*区域的几何变换
affine_trans_region (RegionUnion, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
connection (RegionAffineTrans, ConnectedRegions1)
area_center (ConnectedRegions1, Area, Row1, Column1)
sort_region (ConnectedRegions1, SortedRegions, 'character', 'true', 'row')
*生成一个等差数组
tuple_gen_sequence (1, 49, 1, Sequence)
disp_message (WindowHandle, Sequence, 'image', Row1, Column1, 'black', 'true')

*变换矩阵关系取反
hom_mat2d_invert (HomMat2D, HomMat2DInvert)
*像素坐标的几何变换
affine_trans_pixel (HomMat2DInvert, Row1, Column1, RowTrans, ColTrans)
disp_message (WindowHandle, RowTrans, 'image', RowTrans, ColTrans, 'black', 'true')

row:=[]
col:=[]
startR:=100
startC:=100
step:=70

for r := 1 to 7 by 1
    for c := 1 to 7 by 1
        row:=[row,startR+(r-1)*step]
        col:=[col,startC+(c-1)*step]
    endfor
endfor
vector_to_hom_mat2d (RowTrans, ColTrans, row, col, HomMat2D1)
*图像的几何变换
affine_trans_image (Image, ImageAffineTrans, HomMat2D1, 'constant', 'false')
几何变换与九点标定的应用