Webcam video recording
bruce
New Member Posts: 15 ✭
in Peripherals
Hi, I purchased the UP board a week ago, I am working on a hobby project, I am a novice so I need your guidance.
I want to record a video (using a push button switch for Start/Stop recording) from a webcam connected to one of the USB port. I found this sample code on OpenCV documentation,
Now the problem is that the video doesn't stop by itself, every time I have to press CTRL+C to stop the execution.
Can anyone please guide me how to connect a push button switch with UP board and then execute the code to start and stop the video recording.
I also want to perform some other operation as soon as the recording is being stopped.
I want to record a video (using a push button switch for Start/Stop recording) from a webcam connected to one of the USB port. I found this sample code on OpenCV documentation,
import numpy as np
import cv2
cap = cv2.VideoCapture(0) #webcam defined,
#fourcc = cv2.VideoWritter_fourcc(*'XVID')
fourcc = cv2.cv.CV_FOURCC(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc,30.0,(640,480))
while(True):
ret, frame = cap.read()
#gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'): #
break
cap.release()
out.release()
cv2.destroyAllWindows()
Now the problem is that the video doesn't stop by itself, every time I have to press CTRL+C to stop the execution.
Can anyone please guide me how to connect a push button switch with UP board and then execute the code to start and stop the video recording.
I also want to perform some other operation as soon as the recording is being stopped.
please guide me.
Comments
-
You'll find an example here, for detecting button presses, which might help:
https://up-community.org/wiki/MRAA/UPM#Turn_an_LED_on.2Foff_by_detecting_a_button_press_on_a_GPIO