1 | initial version |
This little program runs with python 3.5 using OpenCV 3.0 and compares image frames from an AVI file, displaying the difference image in a window. The differences are just scaled to fit, but you can come up with all kinds of variations on this.
import numpy as np
import cv2
# Capture video from file
cap=cv2.VideoCapture('/data/Code/Python/AAT/sim_imagery.avi')
old_frame = None
while True:
ret, frame = cap.read()
if ret == True:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
if old_frame is not None:
diff_frame = gray - old_frame
diff_frame -= diff_frame.min()
disp_frame = np.uint8(255.0*diff_frame/float(diff_frame.max()))
cv2.imshow('diff_frame',disp_frame)
old_frame = gray
if cv2.waitKey(30) & 0xFF == ord('q'):
break
else:
print('ERROR!')
break
cap.release()
cv2.destroyAllWindows()