Skip to content

Instantly share code, notes, and snippets.

@ahmedfgad
Created April 10, 2019 22:12
Show Gist options
  • Select an option

  • Save ahmedfgad/26ee739c62aa879d7eac797193473436 to your computer and use it in GitHub Desktop.

Select an option

Save ahmedfgad/26ee739c62aa879d7eac797193473436 to your computer and use it in GitHub Desktop.
import os
import pygame, sys
from pygame.locals import *
import pygame.camera
width = 320
height = 240
# initialise PyGame
pygame.init()
pygame.camera.init()
cam = pygame.camera.Camera("/dev/video0",(width,height))
cam.start()
# Setup a window for displaying the captured images
windowSurfaceObj = pygame.display.set_mode((width,height),1,16)
pygame.display.set_caption('Camera')
# Take a picture
image = cam.get_image()
# Display the picture
catSurfaceObj = image
windowSurfaceObj.blit(catSurfaceObj,(0,0))
pygame.display.update()
pygame.image.save(windowSurfaceObj, './test_picture' + str(k) + '.jpg')
cam.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment