对于斑点检测,你可以使用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