Halcon图像处理入门篇(五)

实际上图像处理的主要作用有两个:1、是获取图像信息 2、是描述图像。入门篇(四)所述特征的描述就是一种描述信息的方式。而本篇要讲的是获取图像信息的一种,即获取图像任意区域或点的位置信息。
映射是图像处理中常用的关系对应方式。其本质就是把图像中的像素坐标与另一个坐标产生一一对应的关系,其数学本质就是线性的矩阵变换:A = WB 主要包括:1、点、线、面、图四者对应的位置及角度变换,

#这里主要演示XY位移映射
dev_update_pc ('off')
dev_update_var ('off')
dev_update_window ('off')
read_image (Image, 'D:/Halcon Example/MVTec/HALCON-18.11-Steady/examples/images/mreut')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_set_part (0, 0, Height - 1, Width - 1)
* Since we are using full_domain below, it is wise to ensure that the
* output images are initialized.
get_system ('init_new_image', InitNewImage)
set_system ('init_new_image', 'true')
for A := 0 to 180 by 1
    * Compute two points on the reflection axis.  The reflection axis goes
    * through the point (Height/2,Width/2) and has the direction A (in
    * degrees).  Note that it is immaterial which two points on the axis
    * are used to define the reflection axis.  In this example, they are
    * chosen in such a way that the reflection axis covers the entire
    * image.  Thus, the two points can be used to visualize the axis below.
    L := 0.75 * max([Width,Height])
    Mr := Height / 2.0
    Mc := Width / 2.0
    Pr := Mr + L * sin(rad(A))
    Pc := Mc - L * cos(rad(A))
    Qr := Mr - L * sin(rad(A))
    Qc := Mc + L * cos(rad(A))
    hom_mat2d_identity (HomMat2DIdentity)
    hom_mat2d_reflect (HomMat2DIdentity, Pr, Pc, Qr, Qc, HomMat2DReflect)
    affine_trans_image (Image, ImageReflect, HomMat2DReflect, 'constant', 'false')
    full_domain (ImageReflect, ImageReflectFull)
    compose3 (Image, ImageReflectFull, Image, ImageColor)
    dev_display (ImageColor)
    dev_set_color ('blue')
    disp_line (WindowHandle, Pr, Pc, Qr, Qc)
endfor
set_system ('init_new_image', InitNewImage)

标定标定是矩阵映射的一种,主要是将图像中的像素坐标映射到另一个坐标系中。详情可以参考张正友标定法。标定过程可以分为有畸变的映射和无畸变的映射,本质上都是在解微分方程,有畸变的映射会考虑畸变偏移量。
1、点映射:

#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)
#2D点仿射
gen_ellipse_contour_xld (ContEllipse, 200, 200, rad(20), 150, 100, rad(0), rad(260), 'positive', 1)
get_contour_xld (ContEllipse, Rows1, Cols1)
* Now we will transform the ellipse by a known transformation and add some
* noise to the coordinates.
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_rotate (HomMat2DIdentity, rad(80), 0, 0, HomMat2DRotate)
hom_mat2d_translate (HomMat2DRotate, 600, 400, HomMat2DTranslate)
hom_mat2d_scale (HomMat2DTranslate, 0.5, 0.5, 0, 0, HomMat2DScale)
affine_trans_point_2d (HomMat2DScale, Rows1, Cols1, Rows2, Cols2)

2、旋转标定

旋转中心标定步骤:
1、获取目标中的稳定 Mark 点
2、将该点旋转固定角度并在图像中获取三个(至少三个点,点越多越准)旋转点坐标
3、将这三个点拟合成圆
4、获取拟合圆的圆心坐标及旋转半径

Row := [0,100.5,100,3] 
Col := [4,0,100,99.4] 
gen_contour_polygon_xld (Contour, Row, Col) 
fit_circle_contour_xld (Contour, 'geotukey', -1, 0, 0, 3, 2, Row_C, Column_C, Radius_C, StartPhi_C, EndPhi_C, PointOrder_C) dev_set_color ('blue') 
gen_circle_contour_xld (ContCircle, Row_C, Column_C, Radius_C, 0, 4 * acos(0), 'positive', 1)
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值