Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Coordinates in contour not Accurate/smooth

I'm working on a people counter system and i'm getting the coordinate of each blob detected through the following code: if area>100: 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,w,h) = cv2.boundingRect(contour) if w>40 and h>40:

    if x>400 and x<450:
        if (abs(prev_x-x))>30:
            cv2.circle(frame,(int(x),int(y)),10,(0,255,0),-1)
            cv2.rectangle(frame, (x,y),(x+10,y+10), (255, 0, 0), 0)
            j=j+1
            prev_x=x

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? If there's a different algorithm available then please do suggest. Thanks.

Coordinates in contour not Accurate/smooth

I'm working on a people counter system and i'm getting the coordinate of each blob detected through the following code: if area>100: 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,w,h) = cv2.boundingRect(contour)
(x,y),radius = cv2.minEnclosingCircle(contour)
      center = (int(x),int(y))
      radius = int(radius)
      if w>40 and h>40:

radius>3:
        cv2.circle(frame,center,1,(0,255,0),-1)
        if x>400 and x<450:
         if (abs(prev_x-x))>30:
            cv2.circle(frame,(int(x),int(y)),10,(0,255,0),-1)
            cv2.rectangle(frame, (x,y),(x+10,y+10), (255, 0, 0), 0)
(abs(prev_x-x))>25:
              cv2.circle(frame,center,1,(0,255,0),-1)
              j=j+1
             prev_x=x

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? If there's a different algorithm available then please do suggest. Thanks.

Coordinates in contour not Accurate/smooth

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:
        cv2.circle(frame,center,1,(0,255,0),-1)
        if x>400 and x<450:
            if (abs(prev_x-x))>25:
              cv2.circle(frame,center,1,(0,255,0),-1)
              j=j+1
              prev_x=x

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? 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.