comments for capture
authorTomas Musil <tomik.musil@gmail.com>
Tue, 24 Jun 2014 02:01:48 +0000 (04:01 +0200)
committerTomas Musil <tomik.musil@gmail.com>
Tue, 24 Jun 2014 02:01:48 +0000 (04:01 +0200)
imago_pack/capture.py

index 7f3234b..3971af5 100755 (executable)
@@ -1,6 +1,10 @@
 #!/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
@@ -16,6 +20,7 @@ import Image
 from camera import Camera
 
 class Screen:
+    """Basic PyGame setup."""
     def __init__(self, res):
         pygame.init()
         pygame.display.set_mode(res)
@@ -23,11 +28,14 @@ class Screen:
         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)
@@ -43,9 +51,9 @@ class Capture:
         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)
@@ -68,11 +76,11 @@ class Capture:
             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
@@ -82,6 +90,7 @@ class Capture:
             clock.tick(15)
 
     def manual(self):
+        """Take images manualy by pressing a key."""
         while True:
             event = pygame.event.wait()
             if event.type == QUIT:
@@ -90,8 +99,8 @@ class Capture:
                 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')
@@ -99,6 +108,7 @@ class Capture:
 
 
 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")
@@ -115,7 +125,6 @@ def main():
 
 
     if args.cmd:
-
         def enqueue_input(queue):
             for line in iter(sys.stdin.readline, b''):
                 queue.put(line)
@@ -128,8 +137,8 @@ def main():
         capture.live(q)
 
         clock = pygame.time.Clock()
-        while True:
 
+        while True:
             try:
                 line = q.get_nowait() # or q.get(timeout=.1)
             except Empty: