利用Halcon取出器件的中心部分,結果如下圖:
主要是利用distance_transform函數,在NI VISION里也有相對應的功能函數。
主要代碼:
read_image (Image, 'C:/Users/gongyong/Desktop/捕獲.PNG')
rgb1_to_gray (Image, GrayImage)
threshold (GrayImage, Regions, 16, 255)
connection (Regions, Connection)
*凸運算,填充區域
shape_trans (Connection, RegionTrans, 'convex')
get_image_size (GrayImage, Width, Height)
*計算一個區域的距離轉換,越往內部的值越高,到圖中為越亮
distance_transform (RegionTrans, DistanceImage, 'city-block', 'true', Width, Height)
reduce_domain (DistanceImage, Regions, ImageReduced)
threshold (ImageReduced, Regions1, 16, 127)
*根據Connection進行連通域分割
intersection (Connection, Regions1, RegionIntersection)