Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3.  
  4. # RECORDER, HOLD 'r' TO RECORD. PRESS 'q' TO EXIT APPLICATION
  5.  
  6. # Chooses which webcam to use, built in computer is 0
  7. cap = cv2.VideoCapture(0)
  8.  
  9. # Video Recorder, with quality
  10. fourcc = cv2.VideoWriter_fourcc(*'XVID')
  11. out = cv2.VideoWriter('Recording.avi', fourcc, 20.0, (640,480))
  12.  
  13. # In a loop to continually record and make each frame gray
  14. while True:
  15.  
  16. # Reads frame
  17. ret, frame = cap.read()
  18.  
  19. # Converts to gray, OPENCV reads BGR not RGB
  20. gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  21.  
  22. # shapes
  23. # cv2.rectangle(frame,(260,190),(390,340),(0,255,0), 2)
  24.  
  25. # Text
  26. font = cv2.FONT_HERSHEY_SIMPLEX
  27. # Shows frame
  28. cv2.imshow("Grayscale (Exit With 'q')", gray)
  29. cv2.imshow("Color (Exit With 'q', hold 'r' to Record)", frame)
  30.  
  31. # Records frame to out
  32. if cv2.waitKey(1) & 0xFF == ord('r'):
  33. out.write(frame)
  34.  
  35. # Checks 1x per frame, if q pressed, closes window
  36. if cv2.waitKey(1) & 0xFF == ord('q'):
  37. break
  38.  
  39. # Ends video
  40. cap.release()
  41.  
  42. # Stops recording
  43. out.release()
  44.  
  45. # Exits windows
  46. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement