halcon计量模型学习1 多计量模型测量线段间距离(轮廓拟合效果较好)

直接上图,和程序,目的为了测量两直线间距离,这里走了点弯路(一个计量模型就可以解决两线段间距离问题,看下一篇)
w

dev_update_off ()
read_image (Image,'C:/Users/连山人/Desktop/标定板图片/Im1.bmp')
dev_close_window ()
get_image_size (Image,Width, Height)
dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_color ('lime green')
dev_set_line_width (3)
dev_display (Image) 

*------------------步骤2:画矩形得直线1----------------------
*创建计量模型需要的数据结构:MetroLineModel;创建的用于测量的数据结构
create_metrology_model (MetroLineModel1)
* 设置计量对象的图像大小(不是必须的,但可以提高第一次测量的运行时间)
set_metrology_model_image_size (MetroLineModel1, Width, Height)

**------------------步骤1:----------------------
 *画一条线
draw_line (WindowHandle, LStartRow1, LStartColumn1, LEndRow1, LEndColumn1)
*将计量的线对象添加到上面创建的模型中
add_metrology_object_line_measure (MetroLineModel1, LStartRow1, LStartColumn1, LEndRow1, LEndColumn1,8, 5, 1, 30, [], [], LineIndices1)
*测量和拟合一个计量模型上测量区域内计量对象的几何形状。
*得到测量区域内度量对象的边缘,并将相应的几何形状拟合到产生的边缘位置
apply_metrology_model (Image, MetroLineModel1)
* 由索引获得该对象在计量模型的测量结果  
*(模型,对象,计量对象的实例类型,泛型参数(允许控制如何返回一个计量对象的结果以及返回什么结果),泛型参数的值,结果值)
get_metrology_object_result (MetroLineModel1, LineIndices1, 'all', 'result_type', 'all_param', LineParameter1)
* 查询测量对象的结果轮廓。
*(给定计量对象的结果轮廓,模型句柄,计量对象的索引,计量对象的实例,相邻轮廓点之间的距离)
get_metrology_object_result_contour (ContoursfittingLine1, MetroLineModel1, 'all', 'all', 1.5)
*提取xld轮廓中点
gen_region_contour_xld (ContoursfittingLine1, RegionLines1, 'filled')
*xld转region
*area_center_points_xld (ContoursfittingLine1, Area, Row, Column)
*提取区域轮骨
skeleton (RegionLines1, Skeleton1)
*获取轮骨端点
junctions_skeleton (RegionLines1, EndPoints1, JuncPoints1)
get_region_points (EndPoints1, Rows1, Columns1)

* 获取计量模型中计量对象的测量区域和边缘位置的结果。
*(测量区域的矩形XLD轮廓,模型句柄,对象索引,选择亮/暗或暗/亮边缘,测量边的坐标)
get_metrology_object_measures (ContoursLine1, MetroLineModel1, 'all', 'all', RowLine1, ColumnLine1)
*为每个输入点生成一个十字形状的XLD轮廓。
*(十字轮廓,行列坐标,长度,方向)
gen_cross_contour_xld (CrossLine1, RowLine1, ColumnLine1, 6, 0.785398)
*显示等高轮廓点十字轮廓
dev_display (CrossLine1)
dev_display (ContoursfittingLine1)
*------------------步骤2:画矩形得直线1----------------------
*创建计量模型需要的数据结构:MetroLineModel;创建的用于测量的数据结构
create_metrology_model (MetroLineModel2)
* 设置计量对象的图像大小(不是必须的,但可以提高第一次测量的运行时间)
set_metrology_model_image_size (MetroLineModel2, Width, Height)

**------------------步骤1:----------------------
 *画一条线
draw_line (WindowHandle, LStartRow2, LStartColumn2, LEndRow2, LEndColumn2)
*将计量的线对象添加到上面创建的模型中
add_metrology_object_line_measure (MetroLineModel2,LStartRow2, LStartColumn2, LEndRow2, LEndColumn2,8, 5, 1, 30, [], [], LineIndices2)
*测量和拟合一个计量模型上测量区域内计量对象的几何形状。
*得到测量区域内度量对象的边缘,并将相应的几何形状拟合到产生的边缘位置
apply_metrology_model (Image, MetroLineModel2)
* 由索引获得该对象在计量模型的测量结果  
*(模型,对象,计量对象的实例类型,泛型参数(允许控制如何返回一个计量对象的结果以及返回什么结果),泛型参数的值,结果值)
get_metrology_object_result (MetroLineModel2, LineIndices2, 'all', 'result_type', 'all_param', LineParameter2)
* 查询测量对象的结果轮廓。
*(给定计量对象的结果轮廓,模型句柄,计量对象的索引,计量对象的实例,相邻轮廓点之间的距离)
get_metrology_object_result_contour (ContoursfittingLine2, MetroLineModel2, 'all', 'all', 1.5)
*xld转region
gen_region_contour_xld (ContoursfittingLine2, RegionLines2, 'filled')
*提取区域轮骨
skeleton (RegionLines2, Skeleton2)
*获取轮骨端点
junctions_skeleton (RegionLines2, EndPoints2, JuncPoints2)
get_region_points (EndPoints2, Rows2, Columns2)

* 获取计量模型中计量对象的测量区域和边缘位置的结果。
*(测量区域的矩形XLD轮廓,模型句柄,对象索引,选择亮/暗或暗/亮边缘,测量边的坐标)
get_metrology_object_measures (ContoursLine2, MetroLineModel2, 'all', 'all', RowLine2, ColumnLine2)
*为每个输入点生成一个十字形状的XLD轮廓。
*(十字轮廓,行列坐标,长度,方向)
gen_cross_contour_xld (CrossLine2, RowLine2, ColumnLine2, 6, 0.785398)
*显示等高轮廓点十字轮廓
dev_display (CrossLine2)
dev_display (ContoursfittingLine2)
*------------------步骤:得两线段最大最小距离----------------------
distance_ss (Rows1[0],Columns1[0], Rows1[1],Columns1[1],Rows2[0],Columns2[0], Rows2[1],Columns2[1], DistanceMin, DistanceMax)

dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, 640, 640, WindowHandle)
disp_obj (Image, WindowHandle)

*显示等高轮廓点十字轮廓
dev_display (CrossLine1)
dev_display (ContoursfittingLine1)
*显示等高轮廓点十字轮廓
dev_display (CrossLine2)
dev_display (ContoursfittingLine2)
*测出距离为像素距离
Message0 := '线段最小距离'+DistanceMin
disp_message (WindowHandle,  Message0, 'window', -1, -1, 'red', 'true')

stop()

以上程序可直接运行,拟合效果也正确,缺点是程序太过繁琐。

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值