Halcon矩阵变换(图像几何变换)

图像几何变换又成称为图像空间变换,包括平移,转置,镜像,旋转,缩放等方式。对图像进行修正,以减小采集系统造成的系统误差或仪器(成像角度,透视关系,镜头等)的随机误差。

下面依次对缩放(hom_mat2d_scale,hom_mat2d_scale_local )平移(hom_mat2d_translate ,hom_mat2d_translate_local)*旋转(hom_mat2d_rotate )投影变换(hom_vector_to_proj_hom_mat2d)进行效果展示

read_image (Image33, 'E:/Halcon/资源图片/33.png')
get_image_size (Image33, Width, Height)
dev_set_draw ('margin')
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image33)
R:=Height/2
C:=Width/2
gen_circle (Circle, R, C, 100.5)

*比例缩放
*hom_mat2d_scale
dev_set_color ('green')
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_scale (HomMat2DIdentity, 2.5, 2.5, R, C, HomMat2DScale)
affine_trans_region (Circle, RegionAffineTrans, HomMat2DScale, 'nearest_neighbor')


*hom_mat2d_scale_local
dev_set_color ('pink')
hom_mat2d_identity (HomMat2DIdentity3)
hom_mat2d_scale_local (HomMat2DIdentity3, 0.5, 0.5, HomMat2DScale1)
affine_trans_region (Circle, RegionAffineTrans2, HomMat2DScale1, 'nearest_neighbor')


*平移
*hom_mat2d_translate
dev_display (Image33)
dev_display (Circle)


dev_set_color ('blue')
hom_mat2d_identity (HomMat2DIdentity1)
hom_mat2d_translate (HomMat2DIdentity1, 0, 100, HomMat2DTranslate)
affine_trans_region (Circle, RegionAffineTrans1, HomMat2DTranslate, 'nearest_neighbor')


dev_set_color ('spring green')
hom_mat2d_identity (HomMat2DIdentity4)
hom_mat2d_translate_local (HomMat2DIdentity4, 0, 200, HomMat2DTranslate1)
affine_trans_region (Circle, RegionAffineTrans2, HomMat2DTranslate1, 'nearest_neighbor')


*旋转
dev_set_color ('red')
dev_display (Image33)
gen_rectangle1 (Rectangle, R-100, C-100, R+100, C+100)


dev_set_color ('green')
hom_mat2d_identity (HomMat2DIdentity2)
hom_mat2d_rotate (HomMat2DIdentity2, rad(45), R, C, HomMat2DRotate)
affine_trans_region (Rectangle, RegionAffineTrans2, HomMat2DRotate, 'nearest_neighbor')

*投影变换
   dev_display (Image33)
   *当前点位
   dev_set_color ('red')
   r:=[R-200,R-300,R+300,R+200,R-200]
   c:=[C-400,C+400,C+400,C-400,C-400]
   

   gen_contour_polygon_xld (Contour, r, c)
   gen_region_contour_xld (Contour, Region111, 'filled')
   rr:=[R-200,R-300,R+300,R+200]
   cc:=[C-400,C+400,C+400,C-400]


   dev_set_color ('blue')
   *目标点位
   r1:=[R-300,R-300,R+300,R+300,R-300]
   c1:=[C-400,C+400,C+400,C-400,C-400]
   gen_contour_polygon_xld (Contour1, r1, c1)


   rr1:=[R-300,R-300,R+300,R+300]
   cc1:=[C-400,C+400,C+400,C-400]
   O:=[1,1,1,1]
   dev_display (Image33)
   dev_set_color ('red')
   dev_display (Contour)
   dev_set_color ('green')
   hom_vector_to_proj_hom_mat2d (rr, cc, O, rr1, cc1, O, 'normalized_dlt', HomMat2D)
   projective_trans_region (Region111, TransRegions, HomMat2D, 'bilinear')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值