Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Webcams and python
- From: sturlamolden at yahoo.no (sturlamolden)
- Subject: Webcams and python
- Date: 18 Mar 2007 13:52:48 -0700
On Mar 18, 8:01 pm, "Synt4x" <ianmurr... at gmail.com> wrote:
> I haven't been able to find the win32api extension, but i've read on
> the web that time.sleep() calls win32api.Sleep().
I tested VideoCapture using PyGame to draw the graphics. PyGame wraps
SDL which uses DirectDraw on Windows. I don't think it matters much,
but DirectX is known to be faster than e.g. GDI and DIB sections.
With 10 fps, I get around 10-15% CPU usage on my laptop. The video
does not look too bad, but it's not perfect. With 20 fps I get 30-40%
CPU usage, and the video looks very smooth. I don't think my webcam
could do any better anyway. CPU use in not anywhere near saturation.
pygame.time.delay() just calls Sleep() in the Windows API, after
setting time resolution to multimedia mode. So adjust the amount of
time you keep the thread asleep.
import VideoCapture
import pygame
from pygame.locals import *
import sys
fps = 20.0
webcam = VideoCapture.Device()
webcam.setResolution(640,480)
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 == QUIT or event.type == KEYDOWN:
sys.exit(0)
im = webcam.getImage()
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))
- References:
- Webcams and python
- From: Synt4x
- Webcams and python
- From: Marc 'BlackJack' Rintsch
- Webcams and python
- From: Synt4x
- Webcams and python
- From: sturlamolden
- Webcams and python
- From: Synt4x
- Webcams and python
- Prev by Date: lock problem
- Next by Date: * operator--as in *args?
- Previous by thread: Webcams and python
- Next by thread: [ANN] GCC 4.1.2 installer for Python distutils compilation
- Index(es):