capture saves images
authorTomas Musil <tomik.musil@gmail.com>
Mon, 30 Apr 2012 22:54:10 +0000 (00:54 +0200)
committerTomas Musil <tomik.musil@gmail.com>
Mon, 30 Apr 2012 22:54:10 +0000 (00:54 +0200)
.gitignore
camera.py
capture.py

index d4cdb45..145e576 100644 (file)
@@ -1,2 +1,3 @@
 *.pyc
 saved
+captured
index 1a7e3b5..ec94787 100644 (file)
--- a/camera.py
+++ b/camera.py
@@ -10,12 +10,16 @@ if os.name == 'posix':
             self._cam = cv.CreateCameraCapture(0)
 
         def get_image(self):
-            im = cv.QueryFrame(self._cam)
+            for _ in range(5): #HACK
+                im = cv.QueryFrame(self._cam)
             # Add the line below if you need it (Ubuntu 8.04+)
             im = cv.GetMat(im)
             #convert Ipl image to PIL image
             return Image.fromstring("RGB", cv.GetSize(im), im.tostring())
         
+        def __del__(self):
+            del self._cam 
+
 
 elif os.name in ('ce', 'nt', 'dos'):
     
index a228ac6..f4283b7 100755 (executable)
@@ -26,12 +26,17 @@ def main():
     cam = Camera()
     screen = Screen()
 
+    im_number = 0
+
     while True:
         event = pygame.event.wait()
         if event.type == QUIT:
             break
         elif event.type == KEYDOWN:
-            screen.display_picture(cam.get_image())
+            im = cam.get_image()
+            screen.display_picture(im)
+            im.save("./captured/{0:0>3}.jpg".format(im_number), 'JPEG')
+            im_number += 1
     
 if __name__ == '__main__':
     try: