4
I’m starting to learn Computer Vision. I’m using the Opencv module for Python 3. Reading tutorials, discover 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 ends by pressing the "q" key. However, I would like a script that saves the video but does not show it. I tried to remove the following line from the script:
cv2.imshow('frame',frame)
It worked, but the script no longer ended when pressing 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?
Comment on the line
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
then change the lineout = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
forout = cv2.VideoWriter('output.avi', -1, 20.0, (640,480))
by changing the second parameter to-1
and see if it works.– gato
When I did this, the difference was: when starting the script, the program asked me to choose a compactor. After I chose it, the program worked the same way as before, @gato
– Benedito
See here on documentation this script, leave a comment here if this script solves your problem.
– gato
The link script you sent me is the same script I want to fix, @cat
– Benedito
At the moment I am without webcan to test, in case nobody responds until Monday I put a reward, but I believe the problem is in the same condition. since the command that closes the loop depends on the window. Seeing this made it clearer to understand, then you have to think of another way.
– gato