I have been using opencv with python for two weeks. I want to find the center of a moving object.
I first find difference from two frame and bitwise bit. After bitwise it came out like a group of white dots around moving object(quad rotor) as you can see in picture below.
So my question is: What method should I use to find the center of a moving object(quad rotor) like in this case?
I thought maybe just find average center of all these dots but I don't know how to do it.
Here is sample picture
Here is my code
import cv2
def diffImg(t0, t1, t2):
d1 = cv2.absdiff(t2, t1)
d2 = cv2.absdiff(t1, t0)
return cv2.bitwise_and(d1, d2)
cam = cv2.VideoCapture('track_outdoor.avi')
winName = "Movement Indicator"
cv2.namedWindow(winName, cv2.CV_WINDOW_AUTOSIZE)
# Read three images first:
t_minus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
t = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
t_plus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
while True:
diff_frame= diffImg(t_minus, t, t_plus)
cv2.imshow( 'Original', t_plus )
cv2.imshow( winName, diff_frame )
# Read next image
t_minus = t
t = t_plus
t_plus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
key = cv2.waitKey(10)
if key == 27:
cv2.destroyWindow(winName)
break
Update #1
first of all thank dervish for answer
I just tried to apply method to find mass center
it work but as dervish it not accurate as I need.
so I came up with another idea if I enchange brightness of diff_frame is it
make more easy,accurate to using method like contours or other method?