H a l c o n 卡 尺 工 具 Halcon卡尺工具 Halcon

注重对add_metrology_object_***的理解,给定坐标后就可以不用自己每次去画

* 获取图像及图像尺寸
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)

* add_metrology_object_line_measure (MetrologyHandle, Row1, Column1, Row2, Column2, 20, 5, 1, 30, [], [], Index1)

* 设置测量对象的参数
* 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)

Halcon卡尺工具_轮廓线