gpt4 book ai didi

python - OpenCV python 的 Blob ID 标记

转载 作者:太空宇宙 更新时间:2023-11-03 23:17:40 30 4
gpt4 key购买 nike

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

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

提前致谢。

最佳答案

对于 Blob 检测,您可以使用 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 - OpenCV python 的 Blob ID 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36619452/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com