Halcon 獲取內圓環圓心|半徑

上結果:
在這裏插入圖片描述
上原圖:
在這裏插入圖片描述
上代碼:

*獲取圖片
read_image (Image, 'D:/HalconWorkplace/img/OCR2.png')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowID)
*二值化
threshold (Image, Region1, 220, 255)
*膨脹腐蝕操作
erosion_rectangle1 (Region1, ccc, 20, 20)
dilation_rectangle1 (ccc, aaa,20, 20)
*像素融合
connection (aaa, ConnectedRegions)
*獲取邊緣
gen_contour_region_xld (ConnectedRegions, Contours, 'border')
*選擇合適大小區域
select_shape(ConnectedRegions, SelectedRegions1, 'circularity', 'and', 0.6, 1)
*獲取取到圓的邊緣
gen_contour_region_xld (SelectedRegions1, ppp, 'border')
*獲取圓面積以及中心座標
area_center (SelectedRegions1, Area, Row,Column)
*獲取包圍圈長度
fuzzy_perimeter (SelectedRegions1,Image, 0, 255, Perimeter)
*求半徑
CRadius:=sqrt(Area/3.1415926)
*求周長
CCircumference := CRadius*2*3.1415926
dev_display(Image)
dev_display(ppp)
*改變字體顏色
dev_set_color ('green') 
*顯示圓心
disp_circle (WindowID, Row, Column, 12)
*顯示文字
set_tposition (WindowID, 200, 350)
write_string (WindowID,'圓心爲:('+Column+','+Row+')')
set_tposition (WindowID, 340, 390)
write_string (WindowID,'半徑爲: '+CRadius)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章