webcam (usb) access under Ubuntu

B

Berco Beute

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:

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
 
D

Diez B. Roggisch

Berco said:
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:


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
 
B

Berco Beute

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
 
D

Diez B. Roggisch

Berco said:
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
 
L

Laurent Pointal

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:


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.
 
B

Berco Beute


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:

===========================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
 
D

Diez B. Roggisch

Berco said:
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
 
B

Berco Beute

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
 
D

Diez B. Roggisch

Berco said:
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
 
Y

yoz

Berco said:
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:


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
 
B

Berco Beute

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
 
T

ticapix

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
 

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top