最近做了個(gè)項(xiàng)目,遇到一個(gè)問題,就是在創(chuàng)建形狀匹配模板時(shí)候,干擾太多,像麻繩一樣。
使用自定義區(qū)域去消除吧,因?yàn)檩喞L,邊緣干擾距離近,操作起來不方便;
使用CAD圖形創(chuàng)建模板吧,又因?yàn)?a target="_blank">產(chǎn)品隨意性比較強(qiáng),每次換產(chǎn)品都要從新畫模板。
最終決定使用手繪模板的方式解決這個(gè)問題。
halcon手繪形狀匹配模板
手繪形狀匹配模板
為了避免大家產(chǎn)生理解歧義,這里對(duì)手繪形狀匹配模板做一個(gè)解釋。
所謂手繪形狀匹配模板,就是在圖像上畫XLD輪廓,將這個(gè)XLD輪廓作為形狀匹配模板。這樣模板就由我們手繪而成,我們想讓模板長什么樣,就把模板畫成什么樣。
主要算子解析
draw_nurbs 繪制平滑曲線
draw_nurbs — 界面交互式繪制平滑曲線
draw_nurbs( : ContOut : WindowHandle, Rotate, Move, Scale, KeepRatio, Degree : Rows, Cols, Weights)
我們一般使用時(shí)參數(shù)設(shè)置如下:
draw_nurbs (ContOut1, WindowHandle, ‘true’, ‘true’, ‘true’, ‘true’, 3, Rows, Cols, Weights)
參數(shù)解釋
ContOut(output_object)xld_cont→對(duì)象
與手繪輪廓近似的NURBS曲線。
WindowHandle(input_control)窗口→(整數(shù))
窗口句柄。
Rotate(input_control)字符串→(string)
旋轉(zhuǎn)使能,輪廓交互時(shí)可以旋轉(zhuǎn)
默認(rèn)值:“ true”
值列表:“ false”,“ true”
Move (input_control)字符串→(string)
移動(dòng)使能,輪廓交互時(shí)可以使能
默認(rèn)值:“ true”
值列表:“ false”,“ true”
Scale(input_control)字符串→(string)
縮放使能,輪廓交互時(shí)可以縮放
默認(rèn)值:“ true”
值列表:“ false”,“ true”
KeepRatio(input_control)字符串→(string)
縮放時(shí)是否保持比例,是否等比例縮放
默認(rèn)值:“ true”
值列表:“ false”,“ true”
Degree(input_control)整數(shù)→(整數(shù))
NURBS曲線的曲度。合理的值是3到25。
默認(rèn)值:3
建議值:2、3、4、5
限制:Degree》 = 2
Rows(output_control)坐標(biāo).y數(shù)組→(真實(shí))
控件多邊形的行坐標(biāo)。
Cols(output_control)坐標(biāo).x數(shù)組→(實(shí)數(shù))
控件多邊形的列坐標(biāo)。
Weights (output_control)實(shí)數(shù)數(shù)組→(實(shí)數(shù))
權(quán)重向量。
create_shape_model_xld 使用XLD輪廓?jiǎng)?chuàng)建模板
create_shape_model_xld — 使用XLD輪廓?jiǎng)?chuàng)建模板
create_shape_model_xld(Contours : : NumLevels, AngleStart, AngleExtent, AngleStep, Optimization, Metric, MinContrast : ModelID)
我們一般使用時(shí)參數(shù)設(shè)置如下:
create_shape_model_xld (Contours , ‘a(chǎn)uto’,-rad(180), rad(360), ‘a(chǎn)uto’, ‘a(chǎn)uto’, ‘ignore_local_polarity’, 10, ModelID)
參數(shù)解釋
Contours (input_object)xld_cont(-array)→對(duì)象
輸入將用于創(chuàng)建模型的輪廓。
NumLevels(input_control)整數(shù)→(整數(shù)/字符串)
金字塔等級(jí)的最大數(shù)量。
默認(rèn)值:“自動(dòng)”
值列表:1、2、3、4、5、6、7、8、9、10,“自動(dòng)”
AngleStart(input_control)angle.rad→(實(shí)數(shù))
模板的起始角度。
默認(rèn)值:-0.39
建議值:-3.14,-1.57,-0.79,-0.39,-0.20、0.0
AngleExtent(input_control)angle.rad→(實(shí)數(shù))
模板旋轉(zhuǎn)角度的范圍。
默認(rèn)值:0.79
建議值:6.29、3.14、1.57、0.79、0.39
限制:AngleExtent》 = 0
AngleStep(input_control)angle.rad→(真實(shí)/字符串)
旋轉(zhuǎn)角度的步長(分辨率)。
默認(rèn)值:“自動(dòng)”
建議值:“自動(dòng)”,0.0175、0.0349、0.0524、0.0698、0.0873
限制:(AngleStep》 0)&&(AngleStep 《=(pi / 16))
Optimization(input_control)字符串(-array)→(string)
一種優(yōu)化,以及用于生成模型的可選方法。
默認(rèn)值:“自動(dòng)”
值列表:“ auto”,“ no_pregeneration”,“ none”,“ point_reduction_high”,“ point_reduction_low”,“ point_reduction_medium”,“ pregeneration”
Metric(input_control)字符串→(string)
匹配指標(biāo)。
默認(rèn)值:‘ignore_local_polarity’
值列表:‘ignore_color_polarity’,‘ignore_global_polarity’,‘ignore_local_polarity’,‘use_polarity’
MinContrast(input_control)編號(hào)→(整數(shù))
搜索圖像中對(duì)象的最小對(duì)比度。
默認(rèn)值:5
建議值:1、2、3、5、7、10、20、30、40
ModelID(輸出控制)shape_model→(整數(shù))
模板的句柄。
實(shí)例演示與解析
實(shí)例代碼展示與解析
*讀入圖片進(jìn)行顯示
read_image (Image, ‘C:/Users/22967/Desktop/ZL2KB/1.bmp’)
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)
*手繪模板
draw_nurbs (ContOut1, WindowHandle, ‘true’, ‘true’, ‘true’, ‘true’, 3, Rows, Cols, Weights)
*使用XLD輪廓?jiǎng)?chuàng)建模板
create_shape_model_xld (ContOut1, ‘a(chǎn)uto’,-rad(180), rad(360), ‘a(chǎn)uto’, ‘a(chǎn)uto’, ‘ignore_local_polarity’, 10, ModelID)
*得到模板輪廓
get_shape_model_contours (ModelContours, ModelID, 1)
*查找模板
find_shape_model (Image, ModelID, 0, 0, 0.8, 0, 0.5, ‘least_squares’, 0, 0.1, Row, Column, Angle, Score)
*顯示查找結(jié)果
if(|Row|==0)
dev_clear_window()
dev_display(Image)
set_tposition (WindowHandle, 300, 300)
write_string (WindowHandle, ‘Not Find’)
stop()else
gen_cross_contour_xld (CrossFind, Row, Column, 200, Angle)
endif
運(yùn)行過程與處理展示
讀入圖像
繪制模板
使用繪制的XLD創(chuàng)建模板
查找模板
編輯:jq
-
CAD
+關(guān)注
關(guān)注
18文章
1093瀏覽量
72777 -
代碼
+關(guān)注
關(guān)注
30文章
4827瀏覽量
69052
原文標(biāo)題:halcon模板匹配干擾邊緣消除辦法
文章出處:【微信號(hào):vision263com,微信公眾號(hào):新機(jī)器視覺】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論