I'm trying to save a screenshot from a camera to a file. I'm using Python 2.7 32 bit and pygame 1.9 32 bit on Windows 8. I spent a while Googling this problem and couldn't find much online.
Here is my code:
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()
And here is the error I am receiving:
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.
I found a list of my webcam's supported resolutions and tried each once of them, none of which worked.
Any help is appreciated, thanks.