projekty
/
imago.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
591bcf6
)
comments for capture
author
Tomas Musil
<tomik.musil@gmail.com>
Tue, 24 Jun 2014 02:01:48 +0000
(
04:01
+0200)
committer
Tomas Musil
<tomik.musil@gmail.com>
Tue, 24 Jun 2014 02:01:48 +0000
(
04:01
+0200)
imago_pack/capture.py
patch
|
blob
|
history
diff --git
a/imago_pack/capture.py
b/imago_pack/capture.py
index
7f3234b
..
3971af5
100755
(executable)
--- a/
imago_pack/capture.py
+++ b/
imago_pack/capture.py
@@
-1,6
+1,10
@@
#!/usr/bin/env python
#!/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
import os
import sys
@@
-16,6
+20,7
@@
import Image
from camera import Camera
class Screen:
from camera import Camera
class Screen:
+ """Basic PyGame setup."""
def __init__(self, res):
pygame.init()
pygame.display.set_mode(res)
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):
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:
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)
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):
del self.cam
def live(self, q):
- done = False
+ """Run live preview on the screen."""
clock = pygame.time.Clock()
clock = pygame.time.Clock()
- while
not done: #live preview
+ while
True:
if q:
try:
line = q.get_nowait() # or q.get(timeout=.1)
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):
clock.tick(5)
def auto(self, interval):
+ """Take new image every *interval* seconds.""" #TODO or is it milisecs?
last = 0
clock = pygame.time.Clock()
last = 0
clock = pygame.time.Clock()
- done = False
- while
not don
e:
+ while
Tru
e:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = 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):
clock.tick(15)
def manual(self):
+ """Take images manualy by pressing a key."""
while True:
event = pygame.event.wait()
if event.type == QUIT:
while True:
event = pygame.event.wait()
if event.type == QUIT:
@@
-90,8
+99,8
@@
class Capture:
continue
self.take()
continue
self.take()
-
def take(self):
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')
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():
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")
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:
if args.cmd:
-
def enqueue_input(queue):
for line in iter(sys.stdin.readline, b''):
queue.put(line)
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()
capture.live(q)
clock = pygame.time.Clock()
- while True:
+ while True:
try:
line = q.get_nowait() # or q.get(timeout=.1)
except Empty:
try:
line = q.get_nowait() # or q.get(timeout=.1)
except Empty: