3

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.

APC
  • 144,005
  • 19
  • 170
  • 281
VDALLCO
  • 168
  • 9
  • According to the docs here: http://www.pygame.org/docs/ref/camera.html , the camera module may be only supported on Linux right now. – Haz Apr 25 '13 at 14:04
  • @cgohlke, Yes I know about the set_mode not having to do with the Camera, but I saw that a possible solution was to set the pygame window to the same resolution as the Camera class. Also your solution didn't work either. Thank you for the response. – VDALLCO Apr 25 '13 at 22:01

0 Answers0