Un piccolo esempio come usare webcam con python
Prima di tutto dobbiamo installare pygame.
1 |
sudo apt-get install python-pygame |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#Importo librerie python import pygame, sys import pygame.camera from pygame.locals import * #Inizializzo la webcam pygame.init() pygame.camera.init() #Setto il display 640x480 screen = pygame.display.set_mode((640,480)) #Creo oggetto WebCam webcam = pygame.camera.Camera("/dev/video0",(640,480)) webcam.start() #Loop per la visualizzazione delle immagini fino che non arriva evento pygame.QUIT while 1: image = webcam.get_image() screen.blit(image,(0,0)) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() |
ottimo, però ho bisogno di capire come attivarne 2 contemporanemente