illume avatar illume committed 7b862f4

Fixed dest_surf on opencv camera driver, added missing methods to vidcap one.

Comments (0)

Files changed (2)

lib/_camera_opencv_highgui.py

 
 import opencv
 #this is important for capturing/displaying images
-from opencv import highgui 
+from opencv import highgui
 
 
 
         #convert Ipl image to PIL image
         #print type(im)
         if im:
-            xx = opencv.adaptors.Ipl2NumPy(im) 
+            xx = opencv.adaptors.Ipl2NumPy(im)
             #print type(xx)
             #print xx.iscontiguous()
             #print dir(xx)
             #print xx.shape
             xxx = numpy.reshape(xx, (numpy.product(xx.shape),))
-      
+
             if xx.shape[2] != 3:
                 raise ValueError("not sure what to do about this size")
 
             # if there is a destination surface given, we blit onto that.
             if dest_surf:
                 dest_surf.blit(pg_img, (0,0))
-            return pg_img
-            #return xxx
-            #return opencv.adaptors.Ipl2PIL(im) 
+            return dest_surf
+            #return pg_img
+
 
 
 if __name__ == "__main__":
     pygame.camera.list_cameras = list_cameras
     pygame.examples.camera.main()
 
-    
 

lib/_camera_vidcapture.py

 import pygame
 
 def list_cameras():
+    return [0]
+
+    # this just cycles through all the cameras trying to open them
     cameras = []
     for x in range(256):
         try:
 
 class Camera:
 
-    def __init__(self, device =0, show_video_window=0):
+    def __init__(self, device =0,
+                       size = (640,480),
+                       mode = "RGB",
+                       show_video_window=0):
         """device:  VideoCapture enumerates the available video capture devices
                     on your system.  If you have more than one device, specify
                     the desired one here.  The device number starts from 0.
                             can not be closed or moved around.
         """
         self.dev = vidcap.new_Dev(device, show_video_window)
+        width, height = size
+        self.dev.setresolution(width, height)
 
     def display_capture_filter_properties(self):
         """Displays a dialog containing the property page of the capture filter.
         """
         return self.dev.getbuffer()
 
+    def start(self):
+        """
+        """
+    def set_controls(self, **kwargs):
+        """
+        """
 
-    def get_surface(self):
+    def stop(self):
+        """
+        """
+
+    def get_image(self, dest_surf = None):
+        return self.get_surface(dest_surf)
+
+    def get_surface(self, dest_surf = None):
         """Returns a pygame Surface.
         """
         abuffer, width, height = self.get_buffer()
 
                 surf = pygame.transform.flip(surf, 0,1)
 
+                # if there is a destination surface given, we blit onto that.
+                if dest_surf:
+                    dest_surf.blit(surf, (0,0))
+                return dest_surf
+
             else:
 
                 # Need to flip the image.
 
 
 if __name__ == "__main__":
+    import pygame.examples.camera
 
-    from pygame.locals import *
-    pygame.init()
+    pygame.camera.Camera = Camera
+    pygame.camera.list_cameras = list_cameras
+    pygame.examples.camera.main()
 
-    #print list_cameras()
-    #raise ""
 
-
-    c = Camera(0)
-    c.set_resolution(640,480)
-    #c.display_capture_pin_properties()
-    #c.display_capture_filter_properties()
-
-
-
-
-    #import time
-    #time.sleep(1.0)
-    screen = pygame.display.set_mode((640,480))
-    clk = pygame.time.Clock()
-
-    going = True
-    while going:
-        events = pygame.event.get()
-        for e in events:
-            if e.type in [QUIT, KEYDOWN]:
-                going = False
-
-        asurf = c.get_surface()
-        screen.blit(asurf, (0,0))
-        pygame.display.flip()
-
-        clk.tick()
-        print clk.get_fps()
-
-
-
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.