halcon脚本-螺丝孔中间小黑圆位置【附源码】
生活随笔
收集整理的這篇文章主要介紹了
halcon脚本-螺丝孔中间小黑圆位置【附源码】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 前言
- 一、原圖
- 二、實現思路
- 三、halcon完整腳本實現
- 四、效果展示
前言
本文對復雜的背景取小圓及其坐標位置
一、原圖
本次檢測的位置如圖:
二、實現思路
本次實驗主要使用區域面積進行獲取,因此思路都比較簡單。
使用閾值,面積選擇,然后得到region,在進行獲得xld,之后再xld中進行擬合圓,得到圓心和半徑。然后繪制圓形
三、halcon完整腳本實現
腳本解析都在代碼里邊可進行查看
dev_close_window() dev_open_window(0, 0, 640, 480, 'black', WindowHandle) for i := 1 to 7 by 1 read_image(Image, i+'.bmp') threshold(Image, Region, 0, 65) * 去除噪點opening_circle(Region, RegionOpening, 10) * 找螺絲孔中間小黑圓位置 connection(RegionOpening, ConnectedRegions)select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 1000, 1550) gen_contour_region_xld(SelectedRegions, Contours, 'border') fit_circle_contour_xld(Contours, 'algebraic', -1, 0, 0, 3, 2, Row1, Column1, Radius, StartPhi, EndPhi, PointOrder) gen_circle(Circle, Row1, Column1, Radius) dev_display(Image) dev_display(Circle) area_center(SelectedRegions, Area, Row, Column) for Index := 0 to |Area|-1 by 1 row:= Row[Index] col:= Column[Index] disp_message(WindowHandle, Index +1+':'+'Row='+Row[Index]+'_Col='+Column[Index], 'image', Row[Index]+50,Column[Index]-200, 'black', 'true') endfor stop() endfor四、效果展示
總結
以上是生活随笔為你收集整理的halcon脚本-螺丝孔中间小黑圆位置【附源码】的全部內容,希望文章能夠幫你解決所遇到的問題。