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
Categories
- 287 All Categories
- 104 Announcements & News
- 47 Product News - New Product/Product Change Notice/ End-of-life
- 179 Welcome Developers!
- 49 Unboxing & Project Sharing
- 18 Tech Updates
- 377 UP Products
- 6 UP Xtreme i11
- 13 UP Squared 6000
- 38 UP Squared Pro
- 126 UP Xtreme
- 796 UP Squared
- 1.4K UP Board
- 86 UP Core Plus
- 217 UP Core
- 3 UP Xtreme Lite
- 40 UP AI Edge
- 213 Starter Kits & Peripheral