图像几何变换-3D图像旋转
在Halcon中,通过projective_trans_image、hom_mat3d_project、hom_mat3d_translate等算子来实现图像的3D旋转。
示例代码如下:
* This program shows how to use hom_mat3d_project and
* projective_trans_image to rotate an image in 3D.
dev_update_pc ('off')
dev_update_window ('off')
dev_update_var ('off')
read_image (Image, 'mreut')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
*Iter := 1440
* 设置旋转角度参数
DAlpha := 1.1
DBeta := 1.3
DGamma := 1.7
Alpha := 60.0
Beta := 0.0
Gamma := 0.0
* 设置相机参数
PrincipalRow := Height / 2
PrincipalColumn := Width / 2
Focus := (Width + Height) / 2
M := 8
N := 3
H := Height / 4.0
W := Width / 4.0
D := (Width + Height) / 6.0
* 3D旋转矩阵参数
hom_mat3d_identity (HomMat3D)
hom_mat3d_rotate (HomMat3D, rad(Gamma), 'z', PrincipalRow, PrincipalColumn, Focus, HomMat3D)
hom_mat3d_rotate (HomMat3D, rad(Beta), 'y', PrincipalRow, PrincipalColumn, Focus, HomMat3D)
hom_mat3d_rotate (HomMat3D, rad(Alpha), 'x', PrincipalRow, PrincipalColumn, Focus, HomMat3D)
T := rad(100.0 / 4.0)
X := H * (cos(N * T) + 0.5 * cos(M * T) * cos(N * T))
Y := W * (sin(N * T) + 0.5 * cos(M * T) * sin(N * T))
Z := D * sin(M * T)
hom_mat3d_translate (HomMat3D, X, Y, Z, HomMat3D)
hom_mat3d_project (HomMat3D, PrincipalRow, PrincipalColumn, Focus, ProjectionMatrix)
* 旋转图像
projective_trans_image (Image, TransImage, ProjectionMatrix, 'bilinear', 'false', 'false')
原始图像:
程序运行结果: