Coordinates in contour not Accurate/smooth

asked 2016-04-20 16:34:09 -0600

kartik gravatar image

updated 2016-04-20 16:39:04 -0600

I'm working on a people counter system and i'm getting the coordinate of each blob detected through the following code:

contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
    try: hierarchy = hierarchy[0]
    except: hierarchy = []
    for contour, hier in zip(contours, hierarchy):
      (x,y),radius = cv2.minEnclosingCircle(contour)
      center = (int(x),int(y))
      radius = int(radius)
      if radius>3:,center,1,(0,255,0),-1)
        if x>400 and x<450:
            if (abs(prev_x-x))>25:

Now the coordinates from the rectangle i'm getting isn't smooth. Moreover the centre of circle i'm getting is'nt stable. Can anyone please suggest a better solution at getting the coordinates of each blob/contour smmothly which is not prone to noise and is stable? Mine is moving too waywardly and the moving of centres arent linear. If there's a different algorithm available then please do suggest. Thanks.

edit retag flag offensive close merge delete


an image will be helpful to understand your question, see Image Moments

sturkmen gravatar imagesturkmen ( 2016-04-20 17:14:56 -0600 )edit