Kartik Madhira
Kartik Madhira

Reputation: 23

Blob ID tagging for OpenCV python

I am currently making a python code for people headcounting with direction. 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. My question regarding the blob detection are:

  1. Is there any blob detection technique for python opencv? Or it could be done with cv2.findContours? I'm working on raspberry pi so could anyone suggest how to get blob library on debian linux?
  2. Even if there is, how could i get a unique ID for each blob? Is there any algorithm to provide tagging of UNIQUE ID's?
  3. If there's any better method to do this, kindly suggest an algorithm.

Thanks in advance.

Upvotes: 1

Views: 1346

Answers (1)

tfv
tfv

Reputation: 6259

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

For labelling, using scipy.ndimage.label is usually a better idea:

label_im, nb_labels = ndimage.label(mask)

Upvotes: 0

Related Questions