首页 > 其他分享 >卡尺找边

卡尺找边

时间:2024-08-28 17:04:38浏览次数:12  
标签:找边 set metrology MetrologyHandle object measure 卡尺 parameter

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.

标签:找边,set,metrology,MetrologyHandle,object,measure,卡尺,parameter
From: https://www.cnblogs.com/wsq484751984/p/18385139

相关文章

  • Java语言程序设计基础篇_编程练习题**15.17 (几何问题:寻找边界矩形)
    **15.17(几何问題:寻找边界矩形)请编写一个程序,让用户可以在一个二维面板上动态地增加和移除点,如图15-29a所示。当点加入和移除的时候,一个最小的边界矩形更新显示。假设每个点的半径是10像素解题思路:这道题可以从编程练习题15.15修改新建一个面板Pane(),方法外部新建一个......
  • opencv卡尺测量原理
    遍历每个矩形区域,分别找到一个灰度突变的峰值,然后把这N个点剔除问题点拟合直线或圆。可以通过卡尺检测边缘,再用投影法,再求灰度平均值沿着边缘检测方向,垂直扫描图像如图......