Webcam video recording

brucebruce Posts: 15New Member
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,
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

Sign In or Register to comment.