winName = 'Movement Indicator'
cv2.namedWindow(winName, cv2.CV_WINDOW_AUTOSIZE)
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:
    cv2.imshow(winName, diffImg(t_minus, t, t_plus))
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
print('Goodbye')
OpenCV detect movement in python