webcam (usb) access under Ubuntu

Discussion in 'Python' started by Berco Beute, Apr 15, 2008.

  1. Berco Beute

    Berco Beute Guest

    I've been trying to access my webcam using Python, but I failed
    miserably. The camera works fine under Ubuntu (using camora and
    skype), but I am unable to get WebCamSpy or libfg to access my webcam.

    First I tried webcamspy (http://webcamspy.sourceforge.net/). That
    requires pySerial and pyParallel, and optionally pyI2C. Runing
    WebCamSpy results in:

    Exception exceptions.AttributeError: "Parallel instance has no
    attribute '_fd'" in <bound method Parallel.__del__ of
    <parallel.parallelppdev.Parallel instance at 0x83326ac>> ignored

    This seems to come from importing I2C. The application window opens,
    but there's an error message:

    NO VIDEO SOURCE FOUND

    Next I tried libfg (http://antonym.org/libfg). I built it, made the
    Python bindings and installed it. Unfortunately the following:

    >>>import fg
    >>>grabber = fg.Grabber()


    results in:

    fg_open(): open video device failed: No such file or directory

    Since the camera works fine in Ubuntu itself my guess is that the
    problem is with the python libraries (or even likelier, my usage of
    them). Is there anybody here that was successful in accessing their
    webcam on linux using Python? Else I have to reside to Windows and
    VideoCapture (which relies on the win32 api and thus is Windows-only),
    something I'd rather not do.

    Thanks for any help,
    2B

    ===============
    I am uUsing:
    WebCam: Logitech QuickCam Pro 400
    Ubuntu
    Python 2.5
     
    Berco Beute, Apr 15, 2008
    #1
    1. Advertising

  2. Berco Beute wrote:

    > I've been trying to access my webcam using Python, but I failed
    > miserably. The camera works fine under Ubuntu (using camora and
    > skype), but I am unable to get WebCamSpy or libfg to access my webcam.
    >
    > First I tried webcamspy (http://webcamspy.sourceforge.net/). That
    > requires pySerial and pyParallel, and optionally pyI2C. Runing
    > WebCamSpy results in:
    >
    > Exception exceptions.AttributeError: "Parallel instance has no
    > attribute '_fd'" in <bound method Parallel.__del__ of
    > <parallel.parallelppdev.Parallel instance at 0x83326ac>> ignored
    >
    > This seems to come from importing I2C. The application window opens,
    > but there's an error message:
    >
    > NO VIDEO SOURCE FOUND
    >
    > Next I tried libfg (http://antonym.org/libfg). I built it, made the
    > Python bindings and installed it. Unfortunately the following:
    >
    >>>>import fg
    >>>>grabber = fg.Grabber()

    >
    > results in:
    >
    > fg_open(): open video device failed: No such file or directory
    >
    > Since the camera works fine in Ubuntu itself my guess is that the
    > problem is with the python libraries (or even likelier, my usage of
    > them). Is there anybody here that was successful in accessing their
    > webcam on linux using Python? Else I have to reside to Windows and
    > VideoCapture (which relies on the win32 api and thus is Windows-only),
    > something I'd rather not do.


    It has been *ages* since I did this - so take it with a grain of salt.
    However, back then I was able to access a video camera using gqcam. Looking
    into the source of that revealed that all it did were some simple
    ioctl-calls and reading from a /dev/video*-device.

    That did the trick for me...

    Additionally, you might consider using gstreamer + the python bindings for
    that. I was also successful using them - if I remember this conversation
    tonight or so, I'll send you the sources.

    Diez

    Diez
     
    Diez B. Roggisch, Apr 15, 2008
    #2
    1. Advertising

  3. Berco Beute

    Berco Beute Guest

    Thanks, that would be great.

    While I'm at it I wondering how to display a video preview. Here's
    someone using VideoCapture (the win32 lib) and PyGame, but I'd rather
    use a GUI framework and preview/capture videos directly.

    2B


    > It has been *ages* since I did this - so take it with a grain of salt.
    > However, back then I was able to access a video camera using gqcam. Looking
    > into the source of that revealed that all it did were some simple
    > ioctl-calls and reading from a /dev/video*-device.
    >
    > That did the trick for me...
    >
    > Additionally, you might consider using gstreamer + the python bindings for
    > that. I was also successful using them - if I remember this conversation
    > tonight or so, I'll send you the sources.
    >
    > Diez
    >
    > Diez
     
    Berco Beute, Apr 15, 2008
    #3
  4. Berco Beute wrote:

    > Thanks, that would be great.
    >
    > While I'm at it I wondering how to display a video preview. Here's
    > someone using VideoCapture (the win32 lib) and PyGame, but I'd rather
    > use a GUI framework and preview/capture videos directly.


    gstreamer has a preview window.

    Diez
     
    Diez B. Roggisch, Apr 15, 2008
    #4
  5. Le Tue, 15 Apr 2008 05:21:54 -0700, Berco Beute a écrit :

    > I've been trying to access my webcam using Python, but I failed
    > miserably. The camera works fine under Ubuntu (using camora and skype),
    > but I am unable to get WebCamSpy or libfg to access my webcam.
    >
    > First I tried webcamspy (http://webcamspy.sourceforge.net/). That
    > requires pySerial and pyParallel, and optionally pyI2C. Runing WebCamSpy
    > results in:
    >
    > Exception exceptions.AttributeError: "Parallel instance has no attribute
    > '_fd'" in <bound method Parallel.__del__ of
    > <parallel.parallelppdev.Parallel instance at 0x83326ac>> ignored
    >
    > This seems to come from importing I2C. The application window opens, but
    > there's an error message:
    >
    > NO VIDEO SOURCE FOUND
    >
    > Next I tried libfg (http://antonym.org/libfg). I built it, made the
    > Python bindings and installed it. Unfortunately the following:
    >
    >>>>import fg
    >>>>grabber = fg.Grabber()

    >
    > results in:
    >
    > fg_open(): open video device failed: No such file or directory
    >
    > Since the camera works fine in Ubuntu itself my guess is that the
    > problem is with the python libraries (or even likelier, my usage of
    > them). Is there anybody here that was successful in accessing their
    > webcam on linux using Python? Else I have to reside to Windows and
    > VideoCapture (which relies on the win32 api and thus is Windows-only),
    > something I'd rather not do.
    >
    > Thanks for any help,


    I dont know if this resolve your problem, but to get snapshots from a
    camera under linux, using V4L2 API, I wrote a small wrapper around this
    API.
    Its called pyvideograb, and its here:
    http://laurent.pointal.org/python/projets/pyvideograb/index.pih

    Note: there is no automatic thing in this library, just a wrapper to
    V4L2, so you must know what options and image format your camera support
    and use these (you may have to convert image by yourself - see PIL and
    Numpy for quick data processing functions). To find the supported options
    you can use xawtv and give it ad-hoc cli option to make it verbose.

    A+

    Laurent.

    --
    Laurent POINTAL -
     
    Laurent Pointal, Apr 15, 2008
    #5
  6. Diez B. Roggisch, Apr 15, 2008
    #6
  7. Berco Beute

    Berco Beute Guest

    On Apr 15, 11:18 pm, "Diez B. Roggisch" <> wrote:
    > Berco Beute schrieb:
    >
    > > Thanks, that would be great.

    >
    > Here you go.
    >
    > http://roggisch.de/vidio.tgz
    >
    > Diez


    Wonderful! Thank you very much!
    I'm running out of time, but after installing the necessary goodies
    using the nice package from here:
    http://aruiz.typepad.com/siliconisland/2006/12/allinone_win32_.html

    In the meantime I've switched to windows. I'm running into the problem
    that 'import gst' throws:

    ===========================
    >>> import gst

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "H:\Python25\lib\site-packages\gst-0.10\gst\__init__.py", line
    87, in <mo
    dule>
    from _gst import *
    ImportError: DLL load failed: The specified module could not be found.

    ===========================

    I've tried reinstalling gstreamer (for windows):

    http://gstreamer.freedesktop.org/pkg/windows/releases/gstreamer/gstreamer-0.10.17.setup.zip
    http://gstreamer.freedesktop.org/pkg/windows/releases/gstreamer/gstreamer-0.10.17.win32.zip

    but that didn't help. I get some complaints about 'libgstinterfaces'
    as well... I'm too unfamiliar with these libraries to have a clue
    what's wrong here...

    I'll look into it some more tomorrow.

    2B
     
    Berco Beute, Apr 15, 2008
    #7
  8. Berco Beute

    Berco Beute Guest

    On Apr 15, 11:45 pm, Berco Beute <> wrote:
    > I've tried reinstalling gstreamer (for windows):
    >
    > http://gstreamer.freedesktop.org/pk...ktop.org/pkg/windows/releases/gstreamer/gstre...
    >
    > but that didn't help. I get some complaints about 'libgstinterfaces'
    > as well...


    To be more precise, when doing an 'import gst' Python shell pops up an
    error dialog saying:

    "This application has failed to start because
    libgstinterfaces-0.10.dll was not found."

    2B
     
    Berco Beute, Apr 16, 2008
    #8
  9. Berco Beute wrote:

    > On Apr 15, 11:45 pm, Berco Beute <> wrote:
    >> I've tried reinstalling gstreamer (for windows):
    >>
    >>

    http://gstreamer.freedesktop.org/pk...ktop.org/pkg/windows/releases/gstreamer/gstre...
    >>
    >> but that didn't help. I get some complaints about 'libgstinterfaces'
    >> as well...

    >
    > To be more precise, when doing an 'import gst' Python shell pops up an
    > error dialog saying:
    >
    > "This application has failed to start because
    > libgstinterfaces-0.10.dll was not found."


    I'm sorry, but I really can't comment on gst-installion issues - that all
    worked for me because of ubuntu.

    Maybe if you are now using windows, there are better options - but I'm a
    *nix-boy :)

    Diez
     
    Diez B. Roggisch, Apr 16, 2008
    #9
  10. Berco Beute

    Berco Beute Guest

    On Apr 16, 12:19 pm, "Diez B. Roggisch" <> wrote:
    > Maybe if you are now using windows, there are better options - but I'm a
    > *nix-boy :)
    >
    > Diez


    So am I :), but the application I'm writing has to run on *that other
    operating system from the 90's*.
    I'm trying hard not to implement the application in C#/.Net, but I'm
    running out of open source alternatives. VideoCapture *almost* worked
    and now I'm stranded at the gstreamer road as well...

    2B
     
    Berco Beute, Apr 16, 2008
    #10
  11. Berco Beute wrote:

    > On Apr 16, 12:19 pm, "Diez B. Roggisch" <> wrote:
    >> Maybe if you are now using windows, there are better options - but I'm a
    >> *nix-boy :)
    >>
    >> Diez

    >
    > So am I :), but the application I'm writing has to run on *that other
    > operating system from the 90's*.
    > I'm trying hard not to implement the application in C#/.Net, but I'm
    > running out of open source alternatives. VideoCapture *almost* worked
    > and now I'm stranded at the gstreamer road as well...


    How's that saying? "If your in Rom, do as the Romans do". Don't fight
    Windows. And take IronPython to mitigate the pain of using it :)

    Diez
     
    Diez B. Roggisch, Apr 16, 2008
    #11
  12. Berco Beute

    yoz Guest

    Berco Beute wrote:
    > I've been trying to access my webcam using Python, but I failed
    > miserably. The camera works fine under Ubuntu (using camora and
    > skype), but I am unable to get WebCamSpy or libfg to access my webcam.
    >
    > First I tried webcamspy (http://webcamspy.sourceforge.net/). That
    > requires pySerial and pyParallel, and optionally pyI2C. Runing
    > WebCamSpy results in:
    >
    > Exception exceptions.AttributeError: "Parallel instance has no
    > attribute '_fd'" in <bound method Parallel.__del__ of
    > <parallel.parallelppdev.Parallel instance at 0x83326ac>> ignored
    >
    > This seems to come from importing I2C. The application window opens,
    > but there's an error message:
    >
    > NO VIDEO SOURCE FOUND
    >
    > Next I tried libfg (http://antonym.org/libfg). I built it, made the
    > Python bindings and installed it. Unfortunately the following:
    >
    >>>> import fg
    >>>> grabber = fg.Grabber()

    >
    > results in:
    >
    > fg_open(): open video device failed: No such file or directory
    >
    > Since the camera works fine in Ubuntu itself my guess is that the
    > problem is with the python libraries (or even likelier, my usage of
    > them). Is there anybody here that was successful in accessing their
    > webcam on linux using Python? Else I have to reside to Windows and
    > VideoCapture (which relies on the win32 api and thus is Windows-only),
    > something I'd rather not do.
    >
    > Thanks for any help,
    > 2B
    >
    > ===============
    > I am uUsing:
    > WebCam: Logitech QuickCam Pro 400
    > Ubuntu
    > Python 2.5



    Some time ago I was playing with writing a webcam server under Linux
    using V4L - I found this bit of code which may help (it works for me).
    Obviously it needs X running to work and the associated libs installed.
    Note this is not my code but it was a good starting point for me to work
    from. I can't find a link to the original article but credit to the author.

    import pygame
    import Image
    from pygame.locals import *
    import sys

    import opencv
    #this is important for capturing/displaying images
    from opencv import highgui

    camera = highgui.cvCreateCameraCapture(0)
    def get_image():
    im = highgui.cvQueryFrame(camera)
    #convert Ipl image to PIL image
    return opencv.adaptors.Ipl2PIL(im)

    fps = 30.0
    pygame.init()
    window = pygame.display.set_mode((320,240))
    pygame.display.set_caption("WebCam Demo")
    screen = pygame.display.get_surface()

    while True:
    events = pygame.event.get()
    for event in events:
    if event.type == QUIT or event.type == KEYDOWN:
    sys.exit(0)
    im = get_image()
    pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode)
    screen.blit(pg_img, (0,0))
    pygame.display.flip()
    pygame.time.delay(int(1000 * 1.0/fps))


    Best of Luck
    Bgeddy
     
    yoz, Apr 16, 2008
    #12
  13. Berco Beute

    Berco Beute Guest

    On Apr 16, 2:26 pm, yoz <> wrote:
    > Berco Beute wrote:
    > > I've been trying to access my webcam using Python, but I failed
    > > miserably. The camera works fine under Ubuntu (using camora and
    > > skype), but I am unable to get WebCamSpy or libfg to access my webcam.

    >
    > > First I tried webcamspy (http://webcamspy.sourceforge.net/). That
    > > requires pySerial and pyParallel, and optionally pyI2C. Runing
    > > WebCamSpy results in:

    >
    > > Exception exceptions.AttributeError: "Parallel instance has no
    > > attribute '_fd'" in <bound method Parallel.__del__ of
    > > <parallel.parallelppdev.Parallel instance at 0x83326ac>> ignored

    >
    > > This seems to come from importing I2C. The application window opens,
    > > but there's an error message:

    >
    > > NO VIDEO SOURCE FOUND

    >
    > > Next I tried libfg (http://antonym.org/libfg). I built it, made the
    > > Python bindings and installed it. Unfortunately the following:

    >
    > >>>> import fg
    > >>>> grabber = fg.Grabber()

    >
    > > results in:

    >
    > > fg_open(): open video device failed: No such file or directory

    >
    > > Since the camera works fine in Ubuntu itself my guess is that the
    > > problem is with the python libraries (or even likelier, my usage of
    > > them). Is there anybody here that was successful in accessing their
    > > webcam on linux using Python? Else I have to reside to Windows and
    > > VideoCapture (which relies on the win32 api and thus is Windows-only),
    > > something I'd rather not do.

    >
    > > Thanks for any help,
    > > 2B

    >
    > > ===============
    > > I am uUsing:
    > > WebCam: Logitech QuickCam Pro 400
    > > Ubuntu
    > > Python 2.5

    >
    > Some time ago I was playing with writing a webcam server under Linux
    > using V4L - I found this bit of code which may help (it works for me).
    > Obviously it needs X running to work and the associated libs installed.
    > Note this is not my code but it was a good starting point for me to work
    > from. I can't find a link to the original article but credit to the author.
    >
    > import pygame
    > import Image
    > from pygame.locals import *
    > import sys
    >
    > import opencv
    > #this is important for capturing/displaying images
    > from opencv import highgui
    >
    > camera = highgui.cvCreateCameraCapture(0)
    > def get_image():
    > im = highgui.cvQueryFrame(camera)
    > #convert Ipl image to PIL image
    > return opencv.adaptors.Ipl2PIL(im)
    >
    > fps = 30.0
    > pygame.init()
    > window = pygame.display.set_mode((320,240))
    > pygame.display.set_caption("WebCam Demo")
    > screen = pygame.display.get_surface()
    >
    > while True:
    > events = pygame.event.get()
    > for event in events:
    > if event.type == QUIT or event.type == KEYDOWN:
    > sys.exit(0)
    > im = get_image()
    > pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode)
    > screen.blit(pg_img, (0,0))
    > pygame.display.flip()
    > pygame.time.delay(int(1000 * 1.0/fps))
    >
    > Best of Luck
    > Bgeddy


    Thank you! That seems to work under both Linux and windows. The opencv
    library is the clue here. I've used the ctypes wrapper for opencv
    provided by the first link below, but there are more options.

    For future reference here are some relevant links:

    http://wwwx.cs.unc.edu/~gb/wp/blog/2007/02/04/python-opencv-wrapper-using-ctypes/
    http://opencvlibrary.sourceforge.net/
    http://opencvlibrary.sourceforge.net/NoamLewis
    http://opencvlibrary.sourceforge.net/PythonInterface

    Windows specific:
    http://www.instructables.com/id/Using-openCV-1.0-with-python-2.5-in-Windows-XP/
    http://dip.sun.ac.za/3Dvision/talks/OpenCV_in_Python_on_Windows.pps
    http://opencvlibrary.sourceforge.net/NoamLewis

    Thanks for all the help.

    2B
     
    Berco Beute, Apr 17, 2008
    #13
  14. Berco Beute

    ticapix Guest

    On 16 avr, 09:41, Berco Beute <> wrote:
    > On Apr 15, 11:45 pm, Berco Beute <> wrote:
    >
    > > I've tried reinstalling gstreamer (for windows):

    >
    > >http://gstreamer.freedesktop.org/pkg/windows/releases/gstreamer/gstre......

    >
    > > but that didn't help. I get some complaints about 'libgstinterfaces'
    > > as well...

    >
    > To be more precise, when doing an 'import gst' Python shell pops up an
    > error dialog saying:
    >
    > "This application has failed to start because
    > libgstinterfaces-0.10.dll was not found."
    >
    > 2B


    You need to install gst-plugins-good too

    --
    pierre
     
    ticapix, May 23, 2008
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. usb webcam event

    , Feb 12, 2007, in forum: Java
    Replies:
    0
    Views:
    326
  2. Speed

    Capture USB Webcam Image

    Speed, Mar 12, 2007, in forum: C++
    Replies:
    4
    Views:
    898
    =?iso-8859-1?q?Erik_Wikstr=F6m?=
    Mar 12, 2007
  3. Speed

    Capture USB Webcam Images using C

    Speed, Mar 12, 2007, in forum: C Programming
    Replies:
    2
    Views:
    1,188
    santosh
    Mar 12, 2007
  4. galapogos
    Replies:
    4
    Views:
    407
    Kenny McCormack
    May 11, 2007
  5. LittleAlex
    Replies:
    0
    Views:
    456
    LittleAlex
    Sep 15, 2008
Loading...

Share This Page