我试着用MS和我的覆盆子-pi-3。当我键入以下命令时,它在命令行上工作:
$ 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代码必须在某个地方更新。你能帮上忙吗?
发布于 2016-12-08 16:53:26
试着用这个:
camera = pygame.camera.Camera(pygame.camera.list_cameras()[0])
camera.start()
img = camera.get_image()
pygame.image.save(img, FILENAME)发布于 2019-01-31 06:55:27
有问题,一旦我停止一个进程使用视频流,错误得到解决。
详细信息
我也有同样的问题。而当
/dev/video0,camera.start()将导致相同的错误。
我跑了
sudo motion早些时候。所以我验证了服务运行,停止了它,然后尝试玩游戏。而且起作用了。
sudo service --status-all
sudo service motion stop发布于 2019-01-31 12:52:04
您还可以使用以下内容:
import cv2
cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)
if vc.isOpened():
rval, frame = vc.read()
else:
rval = False
while rval:
cv2.imshow("preview", frame)
rval, frame = vc.read()
key = cv2.waitKey(20)
if key == 27: # exit on ESC
break
cv2.destroyWindow("preview")https://stackoverflow.com/questions/37926228
复制相似问题