python - Labeled unique contours (or draw independient contours) -


im working in python , opencv library.

i can threshold camera capture, find contours (more one) , draw. have problem. try identify contours unique id or tag. (for example: id: 1 , id:2) track them. need contours use persistent id.

the goal draw line , count more 1 contour , more 1 near contours converts in big one.

note: im working depth camera , image array of depth.

add piece of code.

thanks in advance.

    countours = cv2.findcontours(mask, cv2.retr_external,                                  cv2.chain_approx_simple)[1]      # proceed if @ least 1 contour found     if len(countours) > 0:         # find largest contour in mask, use         # compute minimum enclosing circle ,         # centroid          (i,c) in enumerate(countours):             ((x, y), radius) = cv2.minenclosingcircle(c)              m = cv2.moments(c)             if m["m00"] > 0:                 center = (int(m["m10"] / m["m00"]), int(m["m01"] / m["m00"]))                 centerstring = str(center)                 x = (int(m["m10"] / m["m00"]))                 y = (int(m["m01"] / m["m00"]))             else:                 center = int(x), int(y)                 if radius > 10:                 # draw circle , centroid on frame,                 cv2.circle(frame, (int(x), int(y)), int(radius),                            (0, 255, 255), 2)                 cv2.circle(frame, center, 5, (0, 0, 255), -1)                 # update ponter trail                 if self.previous_position:                     cv2.line(self.trail, self.previous_position, center,                              (255, 255, 255), 2)                     cv2.add(self.trail, frame, frame)                     print center     self.previous_position = center     if len(countours) < 1:         center = 0         self.trail = numpy.zeros((self.cam_height, self.cam_width, 3),                              numpy.uint8)         self.previous_position = none 

two options. first off, contours in python list, indices of list can used enumerate them. in fact you're doing in sense (i,c) in enumerate(countours). can use index i 'color' each contour value i drawing on blank image, , you'll know contour examining image. other, better option imo, use cv2.connectedcomponents() label binary images instead of contours of binary image. pre-labeling might try morphological operations close blobs.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -