如何在rpi3上通过python运行网络摄像头
作者:互联网
我正在尝试使用我的覆盆子-pi-3的MS lifecam.当我输入以下命令时,它在命令行上工作:
$fswebcam img.jpg
Trying source module v4l2...
/dev/video0 opened.
...
Writing JPEG image to 'img.jpg' # this works fine
现在我想通过python代码运行相机:
import pygame
import pygame.camera
from pygame.locals import *
DEVICE = '/dev/video0'
SIZE = (640, 480) # I also tried with img size (384,288), same error
FILENAME = 'capture.jpg'
pygame.init()
pygame.camera.init()
camera = pygame.camera.Camera(DEVICE, SIZE)
camera.start() # error on executing this line
pygame.image.save(screen, FILENAME)
camera.stop()
报告的错误是:
SystemError: ioctl(VIDIOC_S_FMT) failure: no supported formats
我在这里很困惑.相机由rasp-pi支持,所以看起来我的python代码必须在某处更新.你能帮我吗?
解决方法:
试试这个:
camera = pygame.camera.Camera(pygame.camera.list_cameras()[0])
camera.start()
img = camera.get_image()
pygame.image.save(img, FILENAME)
标签:python,raspberry-pi,webcam,raspberry-pi3 来源: https://codeday.me/bug/20190706/1394971.html