From: Tomas Musil Date: Sat, 11 Aug 2012 17:53:33 +0000 (+0200) Subject: camera resolution option X-Git-Url: http://git.tomasm.cz/imago.git/commitdiff_plain/e081eb1ecc06066d8015da7ad40947916607e964?ds=inline camera resolution option --- diff --git a/camera.py b/camera.py index 308ca93..d5dac75 100644 --- a/camera.py +++ b/camera.py @@ -6,8 +6,12 @@ if os.name == 'posix': import cv class Camera: - def __init__(self, vid=0): + def __init__(self, vid=0, res=None): self._cam = cv.CreateCameraCapture(vid) + if res: + cv.SetCaptureProperty(self._cam, cv.CV_CAP_PROP_FRAME_WIDTH, res[0]) + cv.SetCaptureProperty(self._cam, cv.CV_CAP_PROP_FRAME_HEIGHT, + res[1]) def get_image(self): for _ in range(5): #HACK diff --git a/capture.py b/capture.py index b9879d8..ca8da3a 100755 --- a/capture.py +++ b/capture.py @@ -2,6 +2,7 @@ """Go image capture""" +import os import sys import argparse @@ -12,9 +13,9 @@ import Image from camera import Camera class Screen: - def __init__(self): + def __init__(self, res): pygame.init() - pygame.display.set_mode((640,480)) + pygame.display.set_mode(res) pygame.display.set_caption("Go image capture") self._screen = pygame.display.get_surface() @@ -28,13 +29,22 @@ def main(): parser = argparse.ArgumentParser(description=__doc__) 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() - - cam = Camera(vid=args.d) - screen = Screen() + + res=(args.r[0], args.r[1]) + + cam = Camera(vid=args.d, res=res) + screen = Screen(res) im_number = 0 + saving_dir = "./captured/" + + if not os.path.isdir(saving_dir): + os.makedirs(saving_dir) + while True: event = pygame.event.wait() if event.type == QUIT: @@ -42,7 +52,7 @@ def main(): elif event.type == KEYDOWN: im = cam.get_image() screen.display_picture(im) - im.save("./captured/{0:0>3}.jpg".format(im_number), 'JPEG') + im.save(saving_dir + "{0:0>3}.jpg".format(im_number), 'JPEG') im_number += 1 if __name__ == '__main__': diff --git a/imago.py b/imago.py index 61e2558..1cda8ba 100755 --- a/imago.py +++ b/imago.py @@ -127,9 +127,6 @@ def main(): do_something(im_c, "hough x lines") lines.append(hough1.all_lines(im_c)) - print lines[0] - print lines[1] - intersections = intersections_from_angl_dist(lines, image.size) image_g = image.copy() draw = ImageDraw.Draw(image_g)