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)
回到顶部
Result
回到顶部
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 是联动的:
Shape = circle 时,ShapeParam=[Row, Column, Radius]
Shape = rectangle2 时,ShapeParam=[Row, Column, Phi, Length1, Length2]
Shape = ellipse 时,ShapeParam=[Row, Column, Phi, Radius1, Radius2]
Shape = line 时,ShapeParam=[RowBegin, ColumnBegin, RowEnd, ColumnEnd]
set_metrology_object_param( : : MetrologyHandle, Index, GenParamName, GenParamValue : )
创建测量区域的相关参数
measure_length1:The value of this parameter specifies the half length of the measure regions perpendicular to the metrology object boundary.
measure_length2:The value of this parameter specifies the half length of the measure regions tangential to the metrology object boundary.
measure_distance:The value of this parameter specifies the desired distance between the centers of two measure regions.
num_measures:The value of this parameter specifies the desired number of measure regions.
提取边缘的相关参数
measure_sigma:The parameter specifies the sigma for the Gaussian smoothing.
measure_threshold:The parameter specifies the minimum edge amplitude.
measure_select:The parameter specifies the selection of end points of the edges.
measure_transition:The parameter specifies the use of dark/light or light/dark edges.
measure_interpolation:The parameter specifies the type of interpolation to be used.
拟合几何形状的相关参数
min_score: The parameter determines what score a potential instance must at least have to be regarded as a valid instance of the metrology object.
num_instances: The parameter specifies the maximum number of successfully fitted instances of each metrology object after which the fitting will stop.
distance_threshold: apply_metrology_model uses a randomized search algorithm (RANSAC) to fit the geometric shapes.
max_num_iterations: The RANSAC algorithm estimates the number of iterations necessary for fitting the requested geometric shape.
rand_seed: The parameter specifies the seed for the random number generator for the RANSAC algorithm that is used by the selection of the edges the in operator apply_metrology_model.
instances_outside_measure_regions: The parameter specifies the validation of the results of measurements.