1
如何確定在Python 2.7中使用SimpleBlobDetector發現的斑點數量?我有示例代碼查找和標記圖像中的斑點,但也需要知道有多少斑點匹配我的參數。SimpleBlobDetector Blob計數
#!/usr/bin/python
# Standard imports
import cv2
import numpy as np;
from matplotlib import pyplot as plt
# Read image
im = cv2.imread("blob.jpg")
# Setup SimpleBlobDetector parameters.
params = cv2.SimpleBlobDetector_Params()
# Change thresholds
params.minThreshold = 10
params.maxThreshold = 200
# Filter by Area.
params.filterByArea = True
params.minArea = 15
# Filter by Circularity
params.filterByCircularity = True
params.minCircularity = 0.1
# Filter by Convexity
params.filterByConvexity = True
params.minConvexity = 0.87
# Filter by Inertia
params.filterByInertia = True
params.minInertiaRatio = 0.01
# Create a detector with the parameters
detector = cv2.SimpleBlobDetector(params)
# Detect blobs.
keypoints = detector.detect(im)
# 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(im, keypoints, np.array([]), (255,0,0), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS
titles = ['Blobs Detected']
images = [im_with_keypoints]
for i in xrange(1):
plt.subplot(1,1,i+1), plt.imshow(images[i],'gray')
plt.title(titles[i])
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
表現出一定的代碼演示你有什麼到目前爲止已經試過。這會鼓勵其他人提供幫助。 – pczeus
每個關鍵點都是一個blob。只要指出關鍵點。 – Miki