1

我目前正在为有方向的人员编制一个 python 代码。我已经使用“时刻”方法来收集坐标,最终当它越过某条线时,计数器就会增加。但是,这种方法被证明是非常低效的。我关于斑点检测的问题是:

  1. python opencv有没有blob检测技术?或者它可以用 cv2.findContours 来完成?我正在研究树莓派,所以有人可以建议如何在 debian linux 上获取 blob 库吗?
  2. 即使有,我怎样才能获得每个 blob 的唯一 ID?是否有任何算法可以提供唯一 ID 的标记?
  3. 如果有更好的方法可以做到这一点,请提出一种算法。

提前致谢。

4

1 回答 1

0

对于斑点检测,您可以使用 OpenCV 中的 SimpleBlobDetector:

# 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-14T17:01:59.183 回答