argparse for capture
authorTomas Musil <tomik.musil@gmail.com>
Tue, 1 May 2012 18:48:08 +0000 (20:48 +0200)
committerTomas Musil <tomik.musil@gmail.com>
Tue, 1 May 2012 18:48:08 +0000 (20:48 +0200)
camera.py
capture.py

index ec94787..a1be68b 100644 (file)
--- a/camera.py
+++ b/camera.py
@@ -3,17 +3,19 @@ import os
 if os.name == 'posix':
     
     import Image
 if os.name == 'posix':
     
     import Image
-    import cv
+    import cv2.cv as cv
 
     class Camera:
 
     class Camera:
-        def __init__(self):
-            self._cam = cv.CreateCameraCapture(0)
+        def __init__(self, device=0):
+            self._cam = cv.CaptureFromCAM(device)
+            print cv.GetCaptureProperty(self._cam, cv.CV_CAP_PROP_CONVERT_RGB)
+            cv.SetCaptureProperty(self._cam, cv.CV_CAP_PROP_CONVERT_RGB, True)
 
         def get_image(self):
 
         def get_image(self):
-            for _ in range(5): #HACK
+            for _ in range(8): #HACK
                 im = cv.QueryFrame(self._cam)
             # Add the line below if you need it (Ubuntu 8.04+)
                 im = cv.QueryFrame(self._cam)
             # Add the line below if you need it (Ubuntu 8.04+)
-            im = cv.GetMat(im)
+            #im = cv.GetMat(im)
             #convert Ipl image to PIL image
             return Image.fromstring("RGB", cv.GetSize(im), im.tostring())
         
             #convert Ipl image to PIL image
             return Image.fromstring("RGB", cv.GetSize(im), im.tostring())
         
@@ -27,7 +29,7 @@ elif os.name in ('ce', 'nt', 'dos'):
 
     # TODO exception handling
     class Camera:
 
     # TODO exception handling
     class Camera:
-        def __init__(self):
+        def __init__(self, device=0):
             self._cam = Device()
             self._cam.setResolution(640, 480)
 
             self._cam = Device()
             self._cam.setResolution(640, 480)
 
index f4283b7..a4268a0 100755 (executable)
@@ -1,6 +1,9 @@
 #!/usr/bin/env python
 
 #!/usr/bin/env python
 
+"""Go image capture."""
+
 import sys
 import sys
+import argparse
 
 import pygame
 from pygame.locals import QUIT, KEYDOWN
 
 import pygame
 from pygame.locals import QUIT, KEYDOWN
@@ -22,8 +25,19 @@ class Screen:
 
 
 def main():
 
 
 def main():
-    
-    cam = Camera()
+    parser = argparse.ArgumentParser(description=__doc__)
+    #parser.add_argument('file', metavar='file', nargs=1,
+    #                    help="image to analyse")
+    #parser.add_argument('-w', type=int, default=640,
+    #                    help="scale image to the specified width before analysis")
+    parser.add_argument('-d', '--device', type=int, default=0,
+                        help="number of video device to use")
+    #parser.add_argument('-s', '--save', dest='do_something', action='store_const',
+    #                    const=image_save, default=im_debug.show,
+    #                    help="save images instead of displaying them")
+    args = parser.parse_args()
+
+    cam = Camera(device=args.device)
     screen = Screen()
 
     im_number = 0
     screen = Screen()
 
     im_number = 0