Not able to detect all the moving objects in opencv Python

168 Views Asked by At

Using opencv with python! I am trying to create a bounding box across all the objects in the video. I am using find contours . But somehow out of 5 objects, I am not able ti=o detect one, rest all are getting detected.

Here is my code!

contours,hierarchy = cv2.findContours(erosion.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)

for i in contours:

    M = cv2.moments(i)
    cx = int(M['m10']/(M['m00']+0.01))
    cy = int(M['m01'])/(M['m00']+0.01)


    area = cv2.contourArea(i)



    x,y,w,h = cv2.boundingRect(i)

    if w > 5 and h > 5:
        print area
        cv2.rectangle(erosion,(x,y),(x+w,y+h),(255,255,255),1)
0

There are 0 best solutions below