Hi, I'm trying to capture video from an external camera (a webcam for now) during an experiment. This means that within my experiment, I need to start recording without the video feed showing, continue the experiment, and then end the recording at a given point in the experiment.
You can see what I'm doing at the moment below. Now, due to the way the experimental software (opensesame, inline scripts) works, I need to split this routine into one which starts the video recording (but doesn't show the recording) and a separate one, which is called later, which stops and safes the recording.
So, basically, I have two questions: 1) How can I record from the webcam without showing the frame to my particpants? and 2) How can I split this routine into two separate ones: one start routine and one stop and safe routine?
import numpy as np
import cv2 as cv
cap = cv.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
exit()
# Define the codec and create VideoWriter object
fourcc = cv.VideoWriter_fourcc(*'XVID')
out = cv.VideoWriter('figureouthowtoincludevariables.avi', fourcc, 20.0, (640, 480))
while cap.isOpened():
ret, frame = cap.read()
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
frame = cv.flip(frame, 1)
# write the flipped frame
out.write(frame)
cv.imshow('frame', frame)
if cv.waitKey(1) == ord('q'):
break
# Release everything if job is finished
cap.release()
out.release()
cv.destroyAllWindows()