简体   繁体   English

OpenCV python的Blob ID标记

[英]Blob ID tagging for OpenCV python

I am currently making a python code for people headcounting with direction. 我目前正在制作一个python代码,供人们指导方向。 I have used 'moments'method to gather the coordinates and eventually when it crosses a certain line then the counter increments.But, this method is proving to be very inefficient. 我使用'moment'方法来收集坐标,最后当它越过某一条线时,计数器会递增。但是,这种方法被证明是非常低效的。 My question regarding the blob detection are: 我关于斑点检测的问题是:

  1. Is there any blob detection technique for python opencv? 是否有任何针对python opencv的blob检测技术? Or it could be done with cv2.findContours? 或者可以用cv2.findContours完成? I'm working on raspberry pi so could anyone suggest how to get blob library on debian linux? 我正在研究raspberry pi所以有人可以建议如何在debian linux上获取blob库吗?
  2. Even if there is, how could i get a unique ID for each blob? 即使有,我怎么能得到每个blob的唯一ID? Is there any algorithm to provide tagging of UNIQUE ID's? 有没有算法提供UNIQUE ID的标记?
  3. If there's any better method to do this, kindly suggest an algorithm. 如果有更好的方法来做到这一点,请提出一个算法。

Thanks in advance. 提前致谢。

For blob detection you can use SimpleBlobDetector from OpenCV: 对于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)

For labelling, using scipy.ndimage.label is usually a better idea: 对于标签,使用scipy.ndimage.label通常是一个更好的主意:

label_im, nb_labels = ndimage.label(mask)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM