2016-04-14 51 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