camera resolution option
authorTomas Musil <tomik.musil@gmail.com>
Sat, 11 Aug 2012 17:53:33 +0000 (19:53 +0200)
committerTomas Musil <tomik.musil@gmail.com>
Sat, 11 Aug 2012 17:55:46 +0000 (19:55 +0200)
camera.py
capture.py
imago.py

index 308ca93..d5dac75 100644 (file)
--- 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
index b9879d8..ca8da3a 100755 (executable)
@@ -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__':
index 61e2558..1cda8ba 100755 (executable)
--- 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)