Halcon旋转图片的研究

Posted on 2018-03-24 18:02  supercxm  阅读(4326)  评论(0编辑  收藏  举报

在Halcon中有两个用于图像旋转的函数:

1,rotate_image

*Image和ImageRotate分别是输入和输出图像

*Phi是输入的旋转度数

*interpolation是内插方式,默认为'constant'

rotate_image(Image : ImageRotate : Phi, Interpolation : )

2,affine_trans_image

*开辟一个旋转矩阵
(1)hom_mat2d_identity (HomMat2D)
*为旋转矩阵赋值
*HomMat2D是输入的旋转矩阵
*Phi是输入的旋转角度
*Px和Py分别是输入的旋转中心x坐标值和y坐标值
*HomMat2DRotate是输出的旋转矩阵
(2)hom_mat2d_rotate( : : HomMat2D, Phi, Px, Py : HomMat2DRotate)
*实施旋转
*Image : ImageAffinTrans分别为输入输出图像
*HomMat2D是赋值后的旋转矩阵。注意:是赋值后的
*Interpolation是内插方式,默认为'constant' 
*AdaptImageSize是bool变量,判断输出图像的大小是否发生变化
(3)affine_trans_image(Image : ImageAffinTrans : HomMat2D, Interpolation, AdaptImageSize : ) 

但是,在使用过程中,遇到一个问题。在图片进行旋转之后,图片的四个角都不能很好的保留。我想做的是将图片旋转后,将图片不会缺损,也不会缩小,也就是说原图片旋转后将扩大。然后,我找到一种折中的办法,但是速度很慢,也许达不到要求。还是分享记录一下吧。

optimize_aop ('rotate_image', 'byte', 'no_file', ['file_mode','model','parameters'], ['nil','threshold','false'])
set_system ('parallelize_operators', 'true')//只需开一次
get_image_size(image_ori, Width, Height)
gen_rectangle1(Rectangle,0,0,Height-1,Width-1)
get_region_points(Rectangle, Rows, Columns)
***************单通道图像的旋转****************
if(c=1)
    get_grayval(image_ori,Rows,Columns,Grayval)
    HeightL:=3084
    WidthL:=3184
    gen_image_const(Image1, 'byte', WidthL, HeightL)
    Rows:=Rows+(HeightL/2-Height/2)
    Columns:=Columns+(WidthL/2-Width/2)
    set_grayval(Image1,Rows,Columns,Grayval)
    Phi1:=rad(angle)
    vector_angle_to_rigid(HeightL/2, WidthL/2, 0, HeightL/2, WidthL/2, -Phi1, HomMat2D1)
    affine_trans_image(Image1, image_dst, HomMat2D1, 'constant', 'false')
**************3通道彩色图像的旋转**************** elseif(c
=3) decompose3(image_ori, ImageR, ImageG, ImageB) get_grayval(ImageR,Rows,Columns,GrayvalR) get_grayval(ImageG,Rows,Columns,GrayvalG) get_grayval(ImageB,Rows,Columns,GrayvalB) HeightL:=3084 WidthL:=3184 gen_image_const(Image1, 'byte', WidthL, HeightL) gen_image_const(Image2, 'byte', WidthL, HeightL) gen_image_const(Image3, 'byte', WidthL, HeightL) Rows:=Rows+(HeightL/2-Height/2) Columns:=Columns+(WidthL/2-Width/2) set_grayval(Image1,Rows,Columns,GrayvalR) set_grayval(Image2,Rows,Columns,GrayvalG) set_grayval(Image3,Rows,Columns,GrayvalB) compose3(Image1, Image2, Image3, MultiChannelImage) Phi1:=rad(-35) vector_angle_to_rigid(HeightL/2, WidthL/2, 0, HeightL/2, WidthL/2, -Phi1, HomMat2D1) affine_trans_image(MultiChannelImage, image_dst, HomMat2D1, 'constant', 'false') endif

 

Copyright © 2024 supercxm
Powered by .NET 8.0 on Kubernetes