根据两点或多点生成仿射变换

根据两点生成仿射变换

生成椭圆形
gen_ellipse_contour_xld (ContEllipse, 200, 100, rad(60), 70, 95, rad(0), rad(300), 'positive', 1.5)
get_contour_xld (ContEllipse, Row, Col)
*创建一个矩阵
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, 200, 160, HomMat2DTranslate)
affine_trans_contour_xld (ContEllipse, ContoursAffineTrans, HomMat2DTranslate)
hom_mat2d_rotate (HomMat2DTranslate, rad(90), 200, 150, HomMat2DRotate)

affine_trans_contour_xld (ContEllipse, ContoursAffineTrans, HomMat2DRotate)
affine_trans_point_2d (HomMat2DRotate, Col, Row, Col1, Row1)

*生成一个近似的仿射变换矩阵
vector_to_similarity (Col, Row, Col1, Row1, HomMat2D)
affine_trans_contour_xld (ContoursAffineTrans, ContoursAffineTrans1, HomMat2D)

根据两点生成仿射变换2

*生成椭圆形
gen_ellipse_contour_xld (ContEllipse, 200, 100, rad(0), 70, 95, rad(0), rad(360), 'positive', 1.5)
get_contour_xld (ContEllipse, Row, Col)
*根据多个点生成仿射变换矩阵
vector_to_rigid (Col, Row, Col, Row, HomMat2D)

*平移
hom_mat2d_translate (HomMat2D, 50, 150, HomMat2DTranslate)

*仿射变换轮廓
affine_trans_contour_xld (ContEllipse, ContoursAffineTrans, HomMat2DTranslate)

*图像坐标
r:=[455,343,673,34,53]
c:=[354,432,522,32,65]

*物理坐标(机械手)
r1:=[0,2,-2,-1,1]
c1:=[0,1,-4,-2,10]

*生成仿射变换矩阵
vector_to_hom_mat2d (r, c, r1, c1, HomMat2D)
*图像坐标仿射变换为物理坐标
affine_trans_point_2d (HomMat2D, 500, 200, Qx, Qy)
*物理坐标仿射为图像坐标
hom_mat2d_invert (HomMat2D, HomMat2DInvert)
affine_trans_point_2d (HomMat2DInvert,  Qx, Qy, Qx1, Qy1)

计算仿射变换参数

hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, 100, 100, HomMat2DTranslate)

hom_mat2d_scale(HomMat2DTranslate, 5, 5, 0, 0, HomMat2DScale)
hom_mat2d_rotate (HomMat2DScale, rad(90), 0, 0, HomMat2DRotate)
hom_mat2d_slant (HomMat2DRotate, rad(60), 'x', 0, 0, HomMat2DSlant)

hom_mat2d_to_affine_par (HomMat2DSlant, Sx, Sy, Phi, Theta, Tx, Ty)

对XLD轮廓进行仿射变换

dev_clear_window ()
read_image (Image, 'printer_chip/printer_chip_01')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)
threshold (Image, Regions, 155, 255)
connection (Regions, ConnectedRegions)

select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 27496.5, 30201.1)

sort_region (SelectedRegions, SortedRegions, 'character', 'true', 'row')
select_obj (SortedRegions, ObjectSelected,1)

*生成区域轮廓
gen_contour_region_xld (ObjectSelected, Contours, 'border')

*将该区域移动到图像中心
area_center_xld (Contours, Area, Row, Column, PointOrder)

orientation_xld (Contours, Phi)
get_image_size (Image, Width, Height)
vector_angle_to_rigid (Row, Column, Phi, Width/2, Height/2, Phi, HomMat2D)
affine_trans_contour_xld (Contours, ContoursAffineTrans, HomMat2D)
dev_display (Image)
dev_display (ContoursAffineTrans)

转载请注明出处:  https://www.cntworld.cn
智能工控 » 根据两点或多点生成仿射变换

发表回复

提供最优质的资源集合

立即查看 了解详情