see_yourself_camera.py 554 B

1234567891011121314151617181920212223242526
  1. from imutils.video import VideoStream
  2. import cv2
  3. # grab the reference to the webcam
  4. vs = VideoStream(src=0).start()
  5. # keep looping
  6. while True:
  7. # grab the current frame
  8. frame = vs.read()
  9. # if we are viewing a video and we did not grab a frame,
  10. # then we have reached the end of the video
  11. if frame is None:
  12. break
  13. # show the frame to our screen
  14. cv2.imshow("Frame", frame)
  15. key = cv2.waitKey(1) & 0xFF
  16. # if the 'q' or ESC key is pressed, stop the loop
  17. if key == ord("q") or key == 27:
  18. break
  19. # close all windows
  20. cv2.destroyAllWindows()