其他分享
首页 > 其他分享> > halcon卡尺测量

halcon卡尺测量

作者:互联网

 

Code

直线卡尺

 

 

* 获取图像及图像尺寸

dev_close_window ()

read_image (Image, 'fabrik')

get_image_size (Image, Width, Height)

dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)

dev_set_line_width (1)

dev_display (Image)

* 标记测量位置

draw_line (WindowHandle, Row1, Column1, Row2, Column2)

LineParams := [Row1, Column1, Row2, Column2]

 

* 创建测量句柄

create_metrology_model (MetrologyHandle)

 

* 添加测量对象

set_metrology_model_image_size (MetrologyHandle, Width, Height)

add_metrology_object_generic (MetrologyHandle, 'line', LineParams, 20, 3, 1, 30, [], [], Index)

 

* 设置测量对象的参数

* set_metrology_object_param (MetrologyHandle, 'all', 'measure_transition', 'negative')

* set_metrology_object_param (MetrologyHandle, 'all', 'num_measures',10)

* set_metrology_object_param (MetrologyHandle, 'all', 'num_instances', 1)

* set_metrology_object_param (MetrologyHandle, 'all', 'measure_sigma', 1)

* set_metrology_object_param (MetrologyHandle, 'all', 'measure_length1', 20)

* set_metrology_object_param (MetrologyHandle, 'all', 'measure_length2', 5)

* set_metrology_object_param (MetrologyHandle, 'all', 'measure_threshold',30)

* set_metrology_object_param (MetrologyHandle, 'all', 'measure_interpolation', 'bicubic')

* set_metrology_object_param (MetrologyHandle, 'all', 'measure_select', 'all')

* set_metrology_object_param (MetrologyHandle, 'all', 'min_score', 0.7)

 

* 执行测量,获取边缘点集

dev_set_color ('yellow')

apply_metrology_model (Image, MetrologyHandle)

get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Row, Column)

dev_set_color ('red') gen_cross_contour_xld (Cross, Row, Column, 6, 0.785398)

 

* 获取最终测量数据和轮廓线

dev_set_color ('green')

dev_set_line_width (2)

get_metrology_object_result (MetrologyHandle, 'all', 'all', 'result_type', 'all_param', Parameter)

get_metrology_object_result_contour (Contour, MetrologyHandle, 'all', 'all', 1.5)

* 释放测量句柄

clear_metrology_model (MetrologyHandle)

 

Explanation

set_metrology_model_image_size( : : MetrologyHandle, Width, Height : )

使用 set_metrology_model_image_size 该算子设置测量区域,而且该算子必须在 add_metrology_object_generic 这类添加测量对象的算子之前调用,否则在使用 apply_metrology_model 执行测量时会重新计算测量区域,降低效率。

add_metrology_object_generic( : : MetrologyHandle, Shape, ShapeParam, MeasureLength1, MeasureLength2, MeasureSigma, MeasureThreshold, GenParamName, GenParamValue : Index)

参数 Shape 和 ShapeParam 是联动的:

set_metrology_object_param( : : MetrologyHandle, Index, GenParamName, GenParamValue : )

创建测量区域的相关参数

提取边缘的相关参数

拟合几何形状的相关参数

 

标签:MetrologyHandle,set,metrology,object,测量,halcon,measure,卡尺,parameter
来源: https://www.cnblogs.com/DevinXiong/p/15614507.html