#!/usr/bin/env python
-"""Go image capture"""
+"""Go image capture.
+
+This module defines an UI for capturing images with a (web)camera and imediately
+proccessing them with Imago.
+"""
import os
import sys
from camera import Camera
class Screen:
+ """Basic PyGame setup."""
def __init__(self, res):
pygame.init()
pygame.display.set_mode(res)
self._screen = pygame.display.get_surface()
def display_picture(self, im):
+ """Display image on PyGame screen."""
pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode)
self._screen.blit(pg_img, (0,0))
pygame.display.flip()
class Capture:
+ """This object maintains communication between the camera, the PyGame screen
+ and Imago."""
def __init__(self, device, res):
self.cam = Camera(vid=device, res=res)
self.screen = Screen(res)
del self.cam
def live(self, q):
- done = False
+ """Run live preview on the screen."""
clock = pygame.time.Clock()
- while not done: #live preview
+ while True:
if q:
try:
line = q.get_nowait() # or q.get(timeout=.1)
clock.tick(5)
def auto(self, interval):
+ """Take new image every *interval* seconds.""" #TODO or is it milisecs?
last = 0
clock = pygame.time.Clock()
- done = False
- while not done:
+ while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
clock.tick(15)
def manual(self):
+ """Take images manualy by pressing a key."""
while True:
event = pygame.event.wait()
if event.type == QUIT:
continue
self.take()
-
def take(self):
+ """Take a new image from the camera."""
im = self.cam.get_image()
self.screen.display_picture(im)
im.save(self.saving_dir + "{0:0>3}.jpg".format(self.im_number), 'JPEG')
def main():
+ """Parse the argument and setup the UI."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-c', '--cmd', dest='cmd', action='store_true',
help="take commands from stdin")
if args.cmd:
-
def enqueue_input(queue):
for line in iter(sys.stdin.readline, b''):
queue.put(line)
capture.live(q)
clock = pygame.time.Clock()
- while True:
+ while True:
try:
line = q.get_nowait() # or q.get(timeout=.1)
except Empty: