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:
442f568
)
timer + capture
author
Tomas Musil
<tomik.musil@gmail.com>
Sat, 8 Sep 2012 11:37:31 +0000
(13:37 +0200)
committer
Tomas Musil
<tomik.musil@gmail.com>
Sat, 8 Sep 2012 11:37:31 +0000
(13:37 +0200)
capture.py
patch
|
blob
|
history
timer.py
patch
|
blob
|
history
diff --git
a/capture.py
b/capture.py
index
963f6ed
..
a8b6878
100755
(executable)
--- a/
capture.py
+++ b/
capture.py
@@
-6,6
+6,8
@@
import os
import sys
import argparse
import time
import sys
import argparse
import time
+from threading import Thread
+from Queue import Queue, Empty
import pygame
from pygame.locals import QUIT, KEYDOWN
import pygame
from pygame.locals import QUIT, KEYDOWN
@@
-40,16
+42,25
@@
class Capture:
def __del__(self):
del self.cam
def __del__(self):
del self.cam
- def live(self):
+ def live(self
, q
):
done = False
clock = pygame.time.Clock()
while not done: #live preview
done = False
clock = pygame.time.Clock()
while not done: #live preview
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- done = True
- sys.exit()
- if event.type == pygame.KEYDOWN:
- done = True
+ if q:
+ try:
+ line = q.get_nowait() # or q.get(timeout=.1)
+ except Empty:
+ pass
+ else:
+ if line == "stop\n":
+ done = True
+ else:
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ done = True
+ sys.exit()
+ elif event.type == pygame.KEYDOWN:
+ done = True
im = self.cam.get_image()
self.screen.display_picture(im)
im = self.cam.get_image()
self.screen.display_picture(im)
@@
-66,10
+77,7
@@
class Capture:
done = True
if time.time() - last > interval:
last = time.time()
done = True
if time.time() - last > interval:
last = time.time()
- im = self.cam.get_image()
- self.screen.display_picture(im)
- im.save(self.saving_dir + "{0:0>3}.jpg".format(self.im_number), 'JPEG')
- self.im_number += 1
+ self.take()
clock.tick(15)
def manual(self):
clock.tick(15)
def manual(self):
@@
-79,16
+87,20
@@
class Capture:
break
if event.type != KEYDOWN:
continue
break
if event.type != KEYDOWN:
continue
+ self.take()
+
- im = cam.get_image()
-
self.screen.display_picture(im
)
-
im.save(self.saving_dir + "{0:0>3}.jpg".format(self.im_number), 'JPEG'
)
- self.im_number += 1
-
+ def take(self):
+
im = self.cam.get_image(
)
+
self.screen.display_picture(im
)
+ im.save(self.saving_dir + "{0:0>3}.jpg".format(self.im_number), 'JPEG')
+ self.im_number += 1
def main():
parser = argparse.ArgumentParser(description=__doc__)
def main():
parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('-c', '--cmd', dest='cmd', action='store_true',
+ help="take commands from stdin")
parser.add_argument('-d', type=int, default=0,
help="video device id")
parser.add_argument('-a', type=int, default=0,
parser.add_argument('-d', type=int, default=0,
help="video device id")
parser.add_argument('-a', type=int, default=0,
@@
-100,12
+112,41
@@
def main():
res=(args.r[0], args.r[1])
capture = Capture(args.d, res)
res=(args.r[0], args.r[1])
capture = Capture(args.d, res)
- capture.live()
- if args.a > 0:
- capture.auto(args.a)
+ if args.cmd:
+
+ def enqueue_input(queue):
+ for line in iter(sys.stdin.readline, b''):
+ queue.put(line)
+
+ q = Queue()
+ t = Thread(target=enqueue_input, args=(q,))
+ t.daemon = True
+ t.start()
+
+ capture.live(q)
+
+ clock = pygame.time.Clock()
+ while True:
+
+ try:
+ line = q.get_nowait() # or q.get(timeout=.1)
+ except Empty:
+ pass
+ else:
+ if line == "take\n":
+ capture.take()
+ elif line == "exit\n":
+ break
+ clock.tick(10)
+
else:
else:
- capture.manual()
+ capture.live(None)
+ if args.a > 0:
+ capture.auto(args.a)
+ else:
+ capture.manual()
+
del capture
if __name__ == '__main__':
del capture
if __name__ == '__main__':
diff --git
a/timer.py
b/timer.py
index
916d578
..
587b436
100755
(executable)
--- a/
timer.py
+++ b/
timer.py
@@
-6,6
+6,7
@@
import os
import sys
import time
import argparse
import sys
import time
import argparse
+import subprocess
import pygame
import pygame
@@
-45,6
+46,12
@@
class Timer:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-m', type=int, default=45,
help="main time in minutes")
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-m', type=int, default=45,
help="main time in minutes")
+parser.add_argument('-c', '--camera', dest='cam', action='store_true',
+ help="camera on")
+parser.add_argument('-d', type=int, default=0,
+ help="video device id")
+parser.add_argument('-r', type=int, nargs=2, default=[640, 480],
+ help="set camera resolution")
args = parser.parse_args()
args = parser.parse_args()
@@
-64,6
+71,11
@@
main_time = args.m * 60
timers = (Timer(main_time), Timer(main_time))
timers = (Timer(main_time), Timer(main_time))
+if args.cam:
+ capture = subprocess.Popen(['python', 'capture.py', '-c', '-d', str(args.d), '-r',
+ str(args.r[0]),
+ str(args.r[1])], stdin=subprocess.PIPE)
+
while not done:
for event in pygame.event.get():
while not done:
for event in pygame.event.get():
@@
-73,7
+85,12
@@
while not done:
if first:
timers[0].start()
first = False
if first:
timers[0].start()
first = False
+ if args.cam:
+ print >> capture.stdin, "stop"
+ print >> capture.stdin, "take"
continue
continue
+ if args.cam:
+ print >> capture.stdin, "take"
for timer in timers:
if timer.is_running():
timer.stop()
for timer in timers:
if timer.is_running():
timer.stop()
@@
-87,3
+104,6
@@
while not done:
screen.blit(text2, [300, 10])
pygame.display.flip()
clock.tick(15)
screen.blit(text2, [300, 10])
pygame.display.flip()
clock.tick(15)
+
+
+print >> capture.stdin, "exit"