Halcon練手 定位並找圓

2021-10-06 09:23:53 字數 3228 閱讀 6285

模板:

測試:

*亞畫素輪廓

edges_sub_pix (imagereduced, edges, 'canny', 1, 40, 70)

*建立輪廓模板

create_shape_model_xld (edges, 'auto', rad(-180), rad(360), 'auto', 'auto', 'ignore_local_polarity', 5, modelid)

*找模板的輪廓位置

* get_shape_model_contours (modelcontours, modelid, 1)

find_shape_model (imagemodel, modelid, rad(-180), rad(360), 0.5, 1, 0.5, 'least_squares', 0, 0.9, rowmodel, columnmodel, anglemodel, score)

for index := 0 to |imagefiles|-1 by 1

read_image (image, imagefiles[index]

) find_shape_model (image, modelid, rad(-180), rad(360), 0.5, 1, 0.5, 'least_squares', 0, 0.9, rowcur, columncur, anglecur, score)

*得到現在與模板圖 矩陣變化

vector_angle_to_rigid (rowmodel, columnmodel, anglemodel, rowcur, columncur, anglecur, hommat2d)

* hom_mat2d_identity (hommat2didentity)

* hom_mat2d_rotate (hommat2didentity, anglecur, 0, 0, hommat2drotate)

* hom_mat2d_translate (hommat2drotate, rowcur, columncur, hommat2dtranslate)

*將模板輪廓 根據矩陣變化 貼合現在顯示

affine_trans_contour_xld (edges, contoursaffinetrans, hommat2d)

*建立測量模型

create_metrology_model (metrologyhandle)

*模板圖的圓位置roi

* gen_circle (roi_1, 527.164, 705.082, 255.129)

circlerowmodel:=527.164

circlecolumnmodel:=705.082

circleparam:=

[527.164, 705.082, 255.129]

*圓位置變換關係

affine_trans_point_2d (hommat2d, circlerowmodel, circlecolumnmodel,circlerow, circlecolumn)

*新增當前圓的測量模型

*(1)_generic 通用工具 可為圓 矩形 等 'circle' 找圓

* add_metrology_object_generic (metrologyhandle, 'circle', circleparam, 20, 5, 1, 30, [

], [

], index1)

*(2)_circle 新增圓工具 'measure_select'

'measure_select'

add_metrology_object_circle_measure (metrologyhandle, circlerow, circlecolumn, 255.129, 20, 5, 1, 30, 'measure_select', 'first', index1)

*適應模型

*獲取結果

get_metrology_object_result (metrologyhandle, index1, 'all', 'result_type', 'all_param', parameter)

*獲取模型用到的點

get_metrology_object_measures (contours, metrologyhandle, 'all', 'all', row, column)

*取每個卡尺取到的點

gen_cross_contour_xld (cross, row, column, 6, 0.785398)

*點——>輪廓

gen_contour_polygon_xld (contour, row, column)

*擬合圓

Halcon封裝的找邊運算元 靈活好用

我們在做halcon找邊的時候有很多種方式,比如得到想要的邊緣輪廓,然後根據邊緣輪廓擬合邊緣。今天我們講一下另外一種擬合邊的方式。視覺行業的從業者應該都聽過或者用過visionpro,工具化的開發方式,強大的資料流確實好用,再加上很多優化後的工具,在執行時間和穩定性方面做的非常好。但是有時候很你會發...

找老鄉 並查集

認老鄉 大學的同學來自全國各地,對於遠離家鄉步入陌生大學校園的大一新生來說,碰到老鄉是多麼激動的一件事,於是大家都熱衷於問身邊的同學是否與自己同鄉,來自新疆的小賽尤其熱衷。但是大家都不告訴小賽他們來自 只是說與誰同鄉,從所給的資訊中,你能告訴小賽有多少人確定是她的同鄉嗎?輸入 每個測試例項首先包括2...

halcon基於形狀的幾何定位函式說明

1.create shape model template reduce domain後的模板影象 numlevels,金字塔的層數,可設為 auto 或0 10的整數 anglestart,模板旋轉的起始角度 angleextent,模板旋轉角度範圍,0 anglestep,旋轉角度的步長,0 a...