'Why is usb webcam saving blank images in Raspberry pi when display monitor is removed?
I have a python script which captures an image via usb webcam on click of push button. My file is auto executed whenever raspberry pi is powered on, so at to capture images on button click. This auto execution is done using a supervisor service as shown in the link - https://www.techcoil.com/blog/building-a-raspberry-pi-3-prototype-camera-that-takes-a-picture-at-the-press-of-a-button/
Issue - When HDMI display monitor is removed and if the push button is pressed, blank images are getting saved to the path of 0KB size. But if HDMI display monitor is connected to raspberry pi and push button is pressed, actual images from camera are getting saved.
My concern is why are blank images getting saved without display and how can I save real images without connecting the display montior as it is inconvenient to install display over setup.
My working code which saves images every time push button is triggered:
from gpiozero import Button
import cv2
import time
button = Button(4)
cam = cv2.VideoCapture(0)
def take_picture_with_camera():
image_path = '/home/pi/images/pictures/image_%s.jpg' % int(round(time.time() * 1000))
cv2.imwrite(image_path, image)
#print('Took photo')
while (cam.isOpened()):
ret, image =cam.read()
button.when_pressed = take_picture_with_camera
cam.release()
cv2.destroyAllWindows()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
