Skip to content

Instantly share code, notes, and snippets.

@xoxota99
Last active March 3, 2018 05:30
Show Gist options
  • Save xoxota99/46019b359a15e180b18db3e6f4502b57 to your computer and use it in GitHub Desktop.
Save xoxota99/46019b359a15e180b18db3e6f4502b57 to your computer and use it in GitHub Desktop.
Using Videostream causes Flickering
from imutils.video import VideoStream
import cv2
# using VideoStream
vs = VideoStream(0).start()
# time.sleep(2.0)
lastFrame = None
while True:
# grab the frame from the threaded video stream and resize it
frame = vs.read()
# resize
# frame = imutils.resize(frame, width=800)
frame = cv2.resize(frame, (800, 600), fx=0.5, fy=0.5, interpolation=cv2.INTER_LINEAR)
# greyscale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# blur
gray = cv2.GaussianBlur(gray, (21, 21), 0)
if lastFrame is None:
lastFrame = gray
continue
# diff
frameDelta = cv2.absdiff(lastFrame, gray)
lastFrame = gray
thresh = cv2.threshold(frameDelta, 20, 255, cv2.THRESH_BINARY)[1]
# show the output frame
cv2.imshow("thresh", thresh)
key = cv2.waitKey(1) & 0xFF
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment