python - OpenCV python 的 Blob ID 标记

标签 python opencv image-processing cvblobslib

我目前正在为有方向的人员编制 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/

相关文章:

python - 如何捕获扭曲的异常?

c# - 检测阈值区域

c++ - 使用 OpenCV (C++) 在 Xcode 中访问网络摄像头

c++ - GPU 上的高质量图像放大

opencv - 识别图像中的长不规则图案

python - Django:模型设计建议

python - 如何为 Windows 制作 python 模块安装程序?

python - 如何高效地将数千张高清照片加载到 pandas df 中并转换为 HDF?

python - 尝试在 Google App Engine 项目中创建备份时出现 404

opencv - LabVIEW 使用 C DLL 使用 OpenCV DLL