halcon-scaled_shape_model注释

* This example program shows how to find scaled and rotated shape models.
dev_update_pc ('off')
dev_update_window ('off')
dev_update_var ('off')
*读取图像
read_image (Image, 'green-dot')
*获取图像的大小
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_set_color ('red')
dev_display (Image)
*进行阈值分割
threshold (Image, Region, 0, 128)
*连接区域
connection (Region, ConnectedRegions)
*选择感兴趣区域
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10000, 20000)
*充区域内的孔洞 箭头圆形
fill_up (SelectedRegions, RegionFillUp)
*对填充的空洞进行膨胀
dilation_circle (RegionFillUp, RegionDilation, 5.5)
*裁剪膨胀部分 截取的图像是中间那个圆形区域 是创建模板的图像输入参数
reduce_domain (Image, RegionDilation, ImageReduced)
*根据截取部分进行创建变形区域
create_scaled_shape_model (ImageReduced, 5, rad(-45), rad(90), 'auto', 0.8, 1.0, 'auto', 'none', 'ignore_global_polarity', 40, 10, ModelID)
*用于观察模板的轮廓 生成在0 0 位置 具体内容是圆形箭头区域的xld
*Model是affine_trans_contour_xld仿射变换的图像输入参数部分
get_shape_model_contours (Model, ModelID, 1)
*计算填充区域的面积和xy值
area_center (RegionFillUp, Area, RowRef, ColumnRef)
*从点和角度计算刚性仿射变换 RowRef和ColumnRef截取膨胀区域计算得出的值
vector_angle_to_rigid (0, 0, 0, RowRef, ColumnRef, 0, HomMat2D)
*对xld轮廓进行任意仿射2d变换 get_shape_model_contours的
affine_trans_contour_xld (Model, ModelTrans, HomMat2D)
dev_display (Image)
dev_display (ModelTrans)
*读取图像
read_image (ImageSearch, 'green-dots')
dev_display (ImageSearch)
*模板匹配数据
find_scaled_shape_model (ImageSearch, ModelID, rad(-45), rad(90), 0.8, 1.0, 0.5, 0, 0.5, 'least_squares', 5, 0.8, Row, Column, Angle, Scale, Score)
for I := 0 to |Score| - 1 by 1
    *创建转换矩阵
    hom_mat2d_identity (HomMat2DIdentity)
    *平移变换 根据匹配到的row和col进行平移操作
    hom_mat2d_translate (HomMat2DIdentity, Row[I], Column[I], HomMat2DTranslate)
    *旋转变换
    hom_mat2d_rotate (HomMat2DTranslate, Angle[I], Row[I], Column[I], HomMat2DRotate)
    *缩放变换
    hom_mat2d_scale (HomMat2DRotate, Scale[I], Scale[I], Row[I], Column[I], HomMat2DScale)
    *对xld轮廓进行二维仿射变换
    affine_trans_contour_xld (Model, ModelTrans, HomMat2DScale)
    dev_display (ModelTrans)
endfor
clear_shape_model (ModelID)

你可能感兴趣的:(halcon,学习)