Skip to content

Instantly share code, notes, and snippets.

@csvance
Created February 2, 2019 16:25
Show Gist options
  • Save csvance/01136d6cc27142082bf7bcc7173e67ca to your computer and use it in GitHub Desktop.
Save csvance/01136d6cc27142082bf7bcc7173e67ca to your computer and use it in GitHub Desktop.
import cv2
cap = cv2.VideoCapture(0)
final_frame = None
initial_frame = None
while True:
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
final_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
if initial_frame is not None:
diff = cv2.absdiff(initial_frame, final_frame)
cv2.imshow('frame', diff)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
initial_frame = final_frame
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment