By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,016 Members | 2,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,016 IT Pros & Developers. It's quick & easy.

webcam (usb) access under Ubuntu

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
13 Replies


P: n/a
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
Jun 27 '08 #2

P: n/a
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
Jun 27 '08 #3

P: n/a
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
Jun 27 '08 #4

P: n/a
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/pr...grab/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 - la*************@laposte.net
Jun 27 '08 #5

P: n/a
Berco Beute schrieb:
Thanks, that would be great.
Here you go.

http://roggisch.de/vidio.tgz

Diez
Jun 27 '08 #6

P: n/a
On Apr 15, 11:18 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
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/siliconisla...ne_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...0.17.setup.zip
http://gstreamer.freedesktop.org/pkg...0.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
Jun 27 '08 #7

P: n/a
On Apr 15, 11:45 pm, Berco Beute <cybe...@gmail.comwrote:
I've tried reinstalling gstreamer (for windows):

http://gstreamer.freedesktop.org/pkg...streamer/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

Jun 27 '08 #8

P: n/a
Berco Beute wrote:
On Apr 15, 11:45 pm, Berco Beute <cybe...@gmail.comwrote:
>I've tried reinstalling gstreamer (for windows):

http://gstreamer.freedesktop.org/pkg...streamer/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
Jun 27 '08 #9

P: n/a
On Apr 16, 12:19 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
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
Jun 27 '08 #10

P: n/a
Berco Beute wrote:
On Apr 16, 12:19 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
>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
Jun 27 '08 #11

P: n/a
yoz
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
Jun 27 '08 #12

P: n/a
On Apr 16, 2:26 pm, yoz <y...@home.havin.uswrote:
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/2...-using-ctypes/
http://opencvlibrary.sourceforge.net/
http://opencvlibrary.sourceforge.net/NoamLewis
http://opencvlibrary.sourceforge.net/PythonInterface

Windows specific:
http://www.instructables.com/id/Usin...in-Windows-XP/
http://dip.sun.ac.za/3Dvision/talks/...on_Windows.pps
http://opencvlibrary.sourceforge.net/NoamLewis

Thanks for all the help.

2B
Jun 27 '08 #13

P: n/a
On 16 avr, 09:41, Berco Beute <cybe...@gmail.comwrote:
On Apr 15, 11:45 pm, Berco Beute <cybe...@gmail.comwrote:
I've tried reinstalling gstreamer (for windows):
http://gstreamer.freedesktop.org/pkg...streamer/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
Jun 27 '08 #14

This discussion thread is closed

Replies have been disabled for this discussion.