I have a Microsoft USB webcam connected to my raspberry PI 2 B, but sometimes i've got a totally white picture and sometimes a bit of a normal picture. See attachment, it's like the picture is over exposed.
It's something that can be fixed with some changes on the code? I've added already a kind of time before and after that the picture is taken, but that isn't a solution - time.sleep(.)
The code that I currently use
Code: Select all
import os
import pygame, sys
from pygame.locals import *
import pygame.camera
width = 1280
height = 720
#initialise pygame
pygame.init()
pygame.camera.init()
cam = pygame.camera.Camera("/dev/video0",(width,height))
cam.start()
#setup window
windowSurfaceObj = pygame.display.set_mode((width,height),1,32)
pygame.display.set_caption('Camera')
#take a picture
time.sleep(4)
image = cam.get_image()
time.sleep(1)
cam.stop()
#display the picture
catSurfaceObj = image
windowSurfaceObj.blit(catSurfaceObj,(0,0))
pygame.display.update()
#save picture
pygame.image.save(windowSurfaceObj,'/home/pi/python/data/usbwebcamimage.jpg')
Thanks for the feedback!