I'm starting to learn Computer Vision. I'm using the OpenCV module for Python 3. Reading tutorials, I discovered the following script:
import cv2
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
It shows images captured by the webcam and saves them in a video. The script exits by pressing the "q" key. However, I would like a script that would save the video but not show it. I tried to remove the following line from the script:
cv2.imshow('frame',frame)
It worked, but the script did not stop when you pressed the "q" key, because the key must be pressed in the window that opens with the part of the script that I removed. So how can I create a stop condition without creating the window that shows the video?