對於斑點檢測,你可以使用SimpleBlobDetector從OpenCV的:
# Setup SimpleBlobDetector parameters.
params = cv2.SimpleBlobDetector_Params()
# Filter by Area.
params.filterByArea = True
params.minArea = 100
params.maxArea =100000
# Don't filter by Circularity
params.filterByCircularity = False
# Don't filter by Convexity
params.filterByConvexity = False
# Don't filter by Inertia
params.filterByInertia = False
# Create a detector with the parameters
detector = cv2.SimpleBlobDetector_create(params)
# Detect blobs.
keypoints = detector.detect(imthresh)
# Draw detected blobs as red circles.
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures
# the size of the circle corresponds to the size of blob
im_with_keypoints = cv2.drawKeypoints(imthresh, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
標記中使用scipy.ndimage.label通常是一個更好的主意:
label_im, nb_labels = ndimage.label(mask)
來源
2016-04-14 17:01:59
tfv
真的感謝的人。你能詳細說明標籤部分究竟需要做什麼嗎?這條線就夠了,還是要增加一些額外的線?對不起,我是python新手。 –
我已經爲您提供了函數的名稱,您可以使用google輕鬆找到示例代碼,例如在這裏:http://stackoverflow.com/questions/9689173/shape-recognition-with-numpy-scipy-perhaps-watershed – tfv