当显示屏被移除时,为什么 USB 网络摄像头会在 Raspberry pi 中保存空白图像?
我有一个 python 脚本,可以通过单击按钮通过 USB 网络摄像头捕获图像。每当树莓派开机时,我的文件就会自动执行,因此可以在单击按钮时捕获图像。 此自动执行是使用主管服务完成的,如链接所示 - https://www.techcoil.com/blog/building-a-raspberry-pi-3-prototype-camera-that-takes-a-picture-at-the-press-of-a-button/< /a>
问题 - 当 HDMI 显示器被移除并按下按钮时,空白图像将被保存到 0KB 大小的路径中。 但是,如果 HDMI 显示器连接到树莓派并按下按钮,则会保存来自相机的实际图像。
我担心的是为什么在没有显示的情况下保存空白图像以及如何在不连接显示监视器的情况下保存真实图像,因为在设置中安装显示很不方便。
我的工作代码每次触发按钮时都会保存图像:
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()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论