halcon-计量模型-得指定区域内线段长度

重制版
halcon-计量模型-得指定区域内线段长度_第1张图片

dev_update_off ()
read_image (Image,'C:/Users/连山人/Desktop/标定板图片/Image_01.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) 

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

**------------------步骤:----------------------
*画一条线
draw_line (WindowHandle, LStartRow1, LStartColumn1, LEndRow1, LEndColumn1)

Line1 := [LStartRow1, LStartColumn1, LEndRow1, LEndColumn1]
add_metrology_object_generic (MetroLineModel1, 'line', Line1, 7, 5, 1, 30, [], [], LineIndices)
apply_metrology_model (Image, MetroLineModel1)

*获得ContoursLine1(计量模型区域)
get_metrology_object_measures (ContoursLine1, MetroLineModel1, 'all', 'all', RowLine1, ColumnLine1)
*为每个输入点生成一个十字形状的XLD轮廓。
*(十字轮廓,行列坐标,长度,方向)
gen_cross_contour_xld (CrossLine1, RowLine1, ColumnLine1, 6, 0.785398)
* 查询测量对象的结果轮廓。
*(给定计量对象的结果轮廓,模型句柄,计量对象的索引,计量对象的实例,相邻轮廓点之间的距离)
get_metrology_object_result_contour (ContoursfittingLine, MetroLineModel1, 'all', 'all', 1.5)
* 获取每条测量线的起点和终点ParamLine1=='all_param'=((Rsta1,Csta1)(Rend1,Cwend1))
get_metrology_object_result (MetroLineModel1, LineIndices[0], 'all', 'result_type', 'all_param', PLine1)
*线段长度
distance_pp( PLine1[0],PLine1[1], PLine1[2],PLine1[3], Distance)
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, 640, 640, WindowHandle)
disp_obj (Image, WindowHandle)

dev_display (CrossLine1)
dev_display (ContoursfittingLine)

Message0 := '线段像素长度'+Distance
disp_message (WindowHandle,  Message0, 'window', -1, -1, 'red', 'true')

stop()

你可能感兴趣的:(halcon,笔记,图像识别)