Код: Выделить всё
import cv2
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1080)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
writer = cv2.VideoWriter("recording.avi", fourcc, 30.0, (1080, 720))
recording = False
while True:
ret, frame = cap.read()
if ret:
cv2.imshow("video", frame)
if recording:
writer.write(frame)
key = cv2.waitKey(1)
if key == ord('q'):
break
elif key == ord('r'):
recording = not recording
print(f"recording: {recording}")
cap.release()
writer.release()
cv2.destroyAllWindows()
Подробнее здесь: https://stackoverflow.com/questions/791 ... ot-opening
Мобильная версия