[Python-es] Captura de Imagenes WebCam

Carlos Zuniga carlos.zun en gmail.com
Sab Mar 20 23:08:41 CET 2010


2010/3/20 Abraham Zamudio <abraham.zamudio en gmail.com>:
>
> Por alguna razon motion , cuando lo use , hace un par de años me consumio
> muchos recursos . pero sigue siendo una opcion  .
> 2010/3/20 Pablo Angulo <pablo.angulo en uam.es>
>>
>> lopz escribió:
>> > O podrías usar software especial para estos menesteres que igual hay
>> > variedad.
>> >
>> >
>>
>> "motion" es muy fácil de configurar. Básicamente "apt-get install
>> motion", y ya tienes un miniservidor web con imágenes de la webcam.
>> Además sólo actualiza la imagen si detecta movimiento.

También puedes probar con opencv
Aquí un ejemplo que encontré para mostrar la cámara en una ventana de pygame:

import pygame
import Image
import pygame.locals as l
import sys

import opencv.adaptors as adaptors
import opencv
#this is important for capturing/displaying images
from opencv import highgui

camera = highgui.cvCreateCameraCapture(0)
def get_image():
    im = highgui.cvQueryFrame(camera)
    # Add the line below if you need it (Ubuntu 8.04+)
    # im = opencv.cvGetMat(im)
    #convert Ipl image to PIL image
    return adaptors.Ipl2PIL(im)

fps = 30.0
pygame.init()
window = pygame.display.set_mode((640,480))
pygame.display.set_caption("WebCam Demo")
screen = pygame.display.get_surface()

while True:
    events = pygame.event.get()
    for event in events:
        if event.type == l.QUIT or event.type == l.KEYDOWN:
            sys.exit(0)
    im = get_image()
    pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode)
    screen.blit(pg_img, (0,0))
    pygame.display.flip()
    pygame.time.delay(int(1000 * 1.0/fps))


Saludos
-- 
Linux Registered User # 386081
A menudo unas pocas horas de "Prueba y error" podrán ahorrarte minutos
de leer manuales.



Más información sobre la lista de distribución Python-es