[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Proposed Module: Camera



Hi Nirav,


Great work - I've had a go with this, and thought this may be useful.

On Tuesday 03 June 2008 01:27:19 Nirav Patel wrote:
> As of the latest snapshot, it currently supports YUYV and RGB24
> (though that is untested) cameras.  I've tested it so far with vivi
> and the webcam in the OLPC XO.

This doesn't (really) work (yet - but I get a green light come on (more on 
that below...) :) with an Acer laptop's built in camera. It is however 
tanalizingly close...

The camera is identified as this one:

    uvcvideo: Found UVC 1.00 device Acer CrystalEye webcam (064e:a101)
    input: Acer CrystalEye webcam as /class/input/input8
    usbcore: registered new interface driver uvcvideo

Trying the camera using your new module:

>>> import pygame.camera
>>> X=pygame.camera.Camera("/dev/video0", (352, 288)).start()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
EnvironmentError: ioctl(VIDIOC_STREAMON) failure : 71, Protocol error
>>> X=pygame.camera.Camera("/dev/video0", (352, 288)).start()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: ioctl(VIDIOC_S_FMT) failure: no supported formats
>>> X=pygame.camera.Camera("/dev/video0", (352, 288)).start()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: ioctl(VIDIOC_S_FMT) failure: no supported formats

This leaves a green light on though. This green light then stays on until I 
quit the interactive python prompt.

This problem doesn't seem to be specific to your code - I've seen this problem
with other programs including:
    * http://laurent.pointal.org/python/projets/pyvideograb/index.pih
    * opencv
    * Skype (though this has worked at one point)

BUT, since I've had success with it in the past, I also have a positive
(working) case as well which may be of use - using luvcview, I CAN video
from the camera. The manner is a little odd. 

First of all I run it, and it fails:
  ~> luvcview
  luvcview 0.2.4

  SDL information:
    Video driver: x11
    A window manager is available
  Device information:
    Device path:  /dev/video0
  Stream settings:
    Frame format: YUYV (MJPG is not supported by device)
    Frame size:   640x480
    Frame rate:   30 fps
  Unable to start capture: Protocol error
  Error grabbing
  Cleanup done. Exiting ...

When this exits though, it's managed to activate the webcam and hence the 
little green light comes on. Crucially it stays on after the program exits.

When I rerun the same command line:
  ~> luvcview
  luvcview 0.2.4
  
  SDL information:
    Video driver: x11
    A window manager is available
  Device information:
    Device path:  /dev/video0
  Stream settings:
    Frame format: YUYV (MJPG is not supported by device)
    Frame size:   640x480
    Frame rate:   30 fps

Then the program DOES continue to run and capture data, and display video.
When it stops, the light then goes out. (and reruning results in error, and a 
green light left on and so on).

INTERESTINGLY, I *can* get your camera code to work with my webcam *IF* I do 
this:
   1) Run luvcview, and have it crash with the error:
          Unable to start capture: Protocol error
          Error grabbing
          Cleanup done. Exiting ...
       But crash such that it leaves the light on - ie it must leave the
       device active.

   2) *THEN* use your code as follows:
       >>> import pygame.camera
       >>> X=pygame.camera.Camera("/dev/video0", (352, 288))
       >>> X.start()
       >>> Y=X.get_image()
       >>> Y
       <Surface(352x288x24 SW)>
       >>> import pygame
       >>> pygame.init()
       (4, 0)
       >>> display = pygame.display.set_mode((800, 600))
       >>> display.blit(Y, (0,0))
       >>> pygame.display.flip()

This actually makes your code the first such python code I've found that can 
be made (even via a kludge like this) to work with this camera - which is 
really neat :-)

Beyond that, I can extend the above slightly and have basic video using it 
too:
       >>> def get_and_flip():
       ...     Y = X.get_image()
       ...     display.blit(Y, (0,0))
       ...     pygame.display.flip()
       >>> import time
       >>> while 1:
       ...    time.sleep(0.10)
       ...    get_and_flip()
       ...

Which is really fun :)

This means to my mind there's something a little odd about the camera in 
Acers, but it also strikes me that it's something that can be made to work. 
If you have any suggestions of where to look to fix this, I'd be more than 
happy/eager to look into making this reliable.

I suspect I haven't given quite enough information for a clear answer here, so 
please let me know what you need to know, so I can try and figure out how to 
make this work :-)

Great work :-)

Regards,


Michael.