pygame Camera类错误:无法设置捕获分辨率

时间:2013-04-24 23:30:40

标签: python windows-8 pygame webcam

我正在尝试将屏幕截图从相机保存到文件中。我在Windows 8上使用Python 2.7 32位和pygame 1.9 32位。我花了一段时间谷歌搜索这个问题,在网上找不到太多。

这是我的代码:

import pygame
import pygame.camera
import sys

pygame.camera.init()
pygame.display.set_mode((800, 600))
cameraCount = len(pygame.camera.list_cameras())
if cameraCount < 1:
    print "No cameras found!"
    raw_input()
    sys.exit(0)

x = 0

if cameraCount > 1:
    print "Multiple cameras found, choose a number 0 through ", cameraCount
    x = -1
    while int(x) > cameraCount or int(x) < 0:
        x = raw_input()

cam = pygame.camera.Camera(x)
cam.start()
snapshot = cam.get_image()
pygame.image.save(snapshot, "testing.png")
print "done!"
raw_input()

这是我收到的错误:

Traceback (most recent call last):
  File "C:\Users\Cody\Desktop\Python\cameraa.py", line 21, in <module>
    cam = pygame.camera.Camera(x)
  File "C:\Python27\lib\site-packages\pygame\_camera_vidcapture.py", line 52, in
 __init__
    self.dev.setresolution(width, height)
vidcap.Error: Cannot set capture resolution.

我找到了我的网络摄像头支持的分辨率列表,并尝试了一次,但没有一个有效。

感谢任何帮助,谢谢。

0 个答案:

没有答案