2016-04-14 54 views
0

我目前正在制定一个python代码人与人的方向。我用'时刻'的方法来收集坐标,最后当它穿过某条线时,计数器递增。但是,这种方法被证明是非常低效的。我有关斑点检测的问题是:斑点ID标记为OpenCV蟒蛇

  1. python opencv是否有任何斑点检测技术?或者它可以用cv2.findContours完成? 我正在研究覆盆子pi,所以任何人都可以提出如何在debian linux上获得blob库?
  2. 即使有,我怎么能得到每个blob唯一的ID?有没有任何算法来提供标签的唯一ID的?
  3. 如果有更好的方法来做到这一点,请提出一个算法。

在此先感谢。

回答

0

对于斑点检测,你可以使用SimpleBlobDetector从OpenCV的:

# 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) 
+0

真的感谢的人。你能详细说明标签部分究竟需要做什么吗?这条线就够了,还是要增加一些额外的线?对不起,我是python新手。 –

+0

我已经为您提供了函数的名称,您可以使用google轻松找到示例代码,例如在这里:http://stackoverflow.com/questions/9689173/shape-recognition-with-numpy-scipy-perhaps-watershed – tfv