Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import cv2
- # RECORDER, HOLD 'r' TO RECORD. PRESS 'q' TO EXIT APPLICATION
- # Chooses which webcam to use, built in computer is 0
- cap = cv2.VideoCapture(0)
- # Video Recorder, with quality
- fourcc = cv2.VideoWriter_fourcc(*'XVID')
- out = cv2.VideoWriter('Recording.avi', fourcc, 20.0, (640,480))
- # In a loop to continually record and make each frame gray
- while True:
- # Reads frame
- ret, frame = cap.read()
- # Converts to gray, OPENCV reads BGR not RGB
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- # shapes
- # cv2.rectangle(frame,(260,190),(390,340),(0,255,0), 2)
- # Text
- font = cv2.FONT_HERSHEY_SIMPLEX
- # Shows frame
- cv2.imshow("Grayscale (Exit With 'q')", gray)
- cv2.imshow("Color (Exit With 'q', hold 'r' to Record)", frame)
- # Records frame to out
- if cv2.waitKey(1) & 0xFF == ord('r'):
- out.write(frame)
- # Checks 1x per frame, if q pressed, closes window
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- # Ends video
- cap.release()
- # Stops recording
- out.release()
- # Exits windows
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement