I have write down a code that can detect a moving object on a stable background and return a dilated binary spot that can be used to track position in term of x,y coordinates using "cv2.findContours" method in real-time. My problem is that when i run this code it shows two spot one is stable spot which shows the exact initial position of object while one spot continuously moving and showing the current position in real-time. now i just want to show the real-time position rather the the stable spot
import scipy.misc
import cv2
import time
cam = cv2.VideoCapture("VID_20150401_191129.3gp")
r, f1 = cam.read()
f1 = scipy.misc.imresize(f1, 0.4)
while(1):
r2, f2 = cam.read()
f2 = scipy.misc.imresize(f2, 0.4)
frameDelta = cv2.absdiff(f2,f1)
thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.dilate(thresh, None, iterations=4)
cv2.imshow('im',thresh)
k = cv2.waitKey(30) & 0xff
if k == 27:
break