X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/330a8362a13c607e063821f844801b98a6eec514..b0d73e96d68198be32495d7b36505c6d2e3f6810:/capture.py?ds=inline diff --git a/capture.py b/capture.py index bbc3c1e..dbaef64 100755 --- a/capture.py +++ b/capture.py @@ -5,6 +5,7 @@ import os import sys import argparse +import time import pygame from pygame.locals import QUIT, KEYDOWN @@ -29,6 +30,8 @@ def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('-d', type=int, default=0, help="video device id") + parser.add_argument('-a', type=int, default=0, + help="take picture automaticaly every A seconds") parser.add_argument('-r', type=int, nargs=2, default=[640, 480], help="set camera resolution") args = parser.parse_args() @@ -40,16 +43,52 @@ def main(): im_number = 0 - saving_dir = "./captured/" + saving_dir = "./captured/" + time.strftime("%Y-%m-%d %H:%M/") if not os.path.isdir(saving_dir): os.makedirs(saving_dir) - while True: - event = pygame.event.wait() - if event.type == QUIT: - break - elif event.type == KEYDOWN: + done = False + clock = pygame.time.Clock() + while not done: #live preview + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + del cam + sys.exit() + if event.type == pygame.KEYDOWN: + done = True + + im = cam.get_image() + screen.display_picture(im) + clock.tick(5) + + + if args.a > 0: + last = 0 + clock = pygame.time.Clock() + done = False + + while not done: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + if time.time() - last > args.a: + last = time.time() + im = cam.get_image() + screen.display_picture(im) + im.save(saving_dir + "{0:0>3}.jpg".format(im_number), 'JPEG') + im_number += 1 + clock.tick(15) + + else: + while True: + event = pygame.event.wait() + if event.type == QUIT: + break + if event.type != KEYDOWN: + continue + im = cam.get_image() screen.display_picture(im) im.save(saving_dir + "{0:0>3}.jpg".format(im_number), 'JPEG')