Skip to content

Instantly share code, notes, and snippets.

@athena15
Created December 12, 2018 22:57
Show Gist options
  • Save athena15/4da6384ea82c0e49b80cd65e78c1f9bb to your computer and use it in GitHub Desktop.
Save athena15/4da6384ea82c0e49b80cd65e78c1f9bb to your computer and use it in GitHub Desktop.
#starts the webcam, uses it as video source
camera = cv2.VideoCapture(0) #uses webcam for video
while camera.isOpened():
#ret returns True if camera is running, frame grabs each frame of the video feed
ret, frame = camera.read()
k = cv2.waitKey(10)
if k == 32: # if spacebar pressed
frame = np.stack((frame,)*3, axis=-1)
frame = cv2.resize(frame, (224, 224))
frame = frame.reshape(1, 224, 224, 3)
prediction, score = predict_image(frame)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment