10 halcon定位學習(2) 基於元件的匹配

2021-08-08 05:56:13 字數 3444 閱讀 3921

1、  基於元件的匹配

說明:基於元件的匹配是形狀匹配的擴充套件演算法

只有乙個元件會在整個roi 區域搜尋

     其餘元件會根據元件之間的關聯關係去小範圍搜尋

條件:組合物體要包含幾個剛性元件

  元件之間存在一定的位置關係

元件間的關係

• 全影象內搜尋 root component

• 根據root component的位置確定其它元件位置

四個主要函式

◆  訓練函式

train_model_components

◆  建立元件模板函式

create_component_model

create_trained_component_model

◆  搜尋元件模板函式

find_component_model

1》  建立模板

 .確定元件區域

 .建立元件模板

read_image(modelimage,'modules/modules_model')

/…畫四個區域

gen_rectangle2(componentregions,318,109,-1.62,34,19)

gen_rectangle2(rectangle2,342,238,-1.63,32,17)

gen_rectangle2(rectangle3,355,505,1.41,25,17)

gen_rectangle2(rectangle4 247,448,0,14,8)

gen_rectangle2(rectangle5,237,537,-1.57,13,10)

/…將區域合併

componentregions := [componentregions,rectangle2]

componentregions := [componentregions,rectangle3]

componentregions := [componentregions,rectangle4]

componentregions := [componentregions,rectangle5]

/…建立模板

create_component_model(modelimage,componentregions,20,20,rad(25),0,rad(360),15,40,15,10,0.8,[4,3,3,3,3],0,'none','use_polarity','true',componentmodelid,rootranking)

/…將模板寫入位址中

write_component_model(componentmodelid,filename)

2》  查詢模板

 查詢元件模板

read_component_model(filename,componentmodelid)

while(true)

grab_image(searchimage,fghandle)

/…查詢模板

find_component_model(searchimage,componentmodelid,rootranking[0],0,rad(360),0.5,0,0.5,'stop_search','search_from_best','none',0.8,'interpolation',0,0.8,modelstart,modelend,score,rowcomp,columncomp,anglecomp,scorecomp,modelcomp)

dev_display(searchimage)

/…顯示模板輪廓

for match := 0 to |modelstart|-1 by 1

get_found_component_model(foundcomponents,componentmodelid,modelstart,modelend,rowcomp,columncomp,anglecomp,scorecomp,modelcomp,match,'false',rowcompinst,columncompinst,anglecompinst,scorecompinst)

dev_display(foundcomponents)

endfor

endwhile

clear_component_model(componentmodelid)

3》  訓練模板

trainingimages:=

/…讀入四張

for i :=1 to 4 by 1

read_image(trainingimage,'pipe_wrench_training_'+i)

trainingimages := [trainingimages,trainingimage]

endfor

/…訓練模板

train_model_components(modelimage,initialcomponentregions,trainingimages,modelcomponents,22,60,30,0.65,-1,1,rad(60),'speed','rigidity',0.2,0.4,componenttrainingid)

write_training_components(componenttrainingid,filenametraining)

/…通過訓練結果建立模板

read_training_components(filenametraining,componenttrainingid)

create_trained_component_model(componenttrainingid,-rad(30),rad(60),10,0.55,4,0,'none','use_polarity','false',componentmodelid,rootranking)

write_component_model(componentmodelid,filename)

clear_training_components(componenttrainingid)

注釋:train_model_components(

modelimage, // 模板

initialcomponents, // 根元件

trainingimages,  // 訓練

modelcomponents,  // 元件模板

contrastlow, contrasthigh,  //同形狀模板

minsize, minscore, // 同形狀模板

searchrowtol, searchcolumntol, // 位置變化範圍

searchangletol,  // 角度變化範圍

trainingemphasis, // 速度或魯棒性優先

ambiguitycriterion, // 模糊匹配規則

maxcontouroverlap, // 輪廓重合

clusterthreshold,  // 根元件歸類閾值

componenttrainingid  // 模板id

9 halcon定位學習(1) 基於形狀的匹配

1 基於形狀的匹配 1 建立roi 使用halcon 運算元可以方便的設定roi 標準形狀 draw rectangle1 2 draw circle draw ellipse draw line 任意形狀 draw region draw polygon 生成標準roi gen rectangle...

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

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

關於halcon基於表面的3d識別定位

基於表面的3d識別定位,即在乙個3d 場景下,用3d表面模型去識別零件,得到零件的pose,這個pose是基於3d場景座標系的。模型可以用solidworks軟體畫,儲存成.stl格式,也可以是程式生成的。讀入檔案然後生成3d表面模型 file 零件模型的位址及名稱 mm 也可以是 m dm 設定成...