OpenCV 的 Blob ID 标记 python
Blob ID tagging for OpenCV python
我目前正在制作一个 python 人员人数统计代码。我已经使用“时刻”方法来收集坐标,最终当它穿过某条线时,然后是计数器 increments.But,这种方法被证明是非常低效的。我关于斑点检测的问题是:
- python opencv 是否有任何 blob 检测技术?或者可以用 cv2.findContours 来完成?
我正在研究 raspberry pi 所以有人可以建议如何在 debian linux 上获取 blob 库吗?
- 即使有,我如何为每个 blob 获取唯一 ID?是否有任何算法可以提供唯一 ID 的标记?
- 如果有更好的方法,请提出算法。
提前致谢。
对于斑点检测,您可以使用 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)
我目前正在制作一个 python 人员人数统计代码。我已经使用“时刻”方法来收集坐标,最终当它穿过某条线时,然后是计数器 increments.But,这种方法被证明是非常低效的。我关于斑点检测的问题是:
- python opencv 是否有任何 blob 检测技术?或者可以用 cv2.findContours 来完成? 我正在研究 raspberry pi 所以有人可以建议如何在 debian linux 上获取 blob 库吗?
- 即使有,我如何为每个 blob 获取唯一 ID?是否有任何算法可以提供唯一 ID 的标记?
- 如果有更好的方法,请提出算法。
提前致谢。
对于斑点检测,您可以使用 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)