What I have? I have a code that detects the biggest object in the video.
How do I do it? I am using knn filter, findControus, contourArea and boundingRect to detect and draw a rectangle around of the biggest object.
My problem: Sometimes my object changes the speed, then another object gets more 'background subtraction difference' and it misses the real target.
I was thinking how can I keep following only this guy. I tried to use a keyboard input to tell to my code who is the right guy, and then keep following it. But it didn't work.
The reason that I need to track only one is because I need to make an analysis based on its coordinate.
This is my code:
maximumArea = 0
bestContour = None
for contour in contours:
currentArea = cv2.contourArea(contour)
if currentArea > maximumArea:
bestContour = contour
maximumArea = currentArea
if bestContour is not None:
x,y,w,h = cv2.boundingRect(bestContour)
cv2.rectangle(orig_img, (x,y),(x+w,y+h), (0,0,255), 3)
print("The X, Y coordinate is: %s , %s " % (x, y))
f = open("hello.txt", "a")
f.write("\n" "%s %s" % (x, y))
f.close()