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.
轉載于:https://www.cnblogs.com/zdfffg/p/11572249.html
總結
以上是生活随笔為你收集整理的Halcon - 定位 - 卡尺的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 视觉硬件 - 相机 镜头 选型
- 下一篇: AI 趋势