Webcam + GStreamer
Sparky
Samnsparky at gmail.com
Sun Jul 12 20:01:55 EDT 2009
On Jul 12, 4:30 pm, David <da... at pythontoo.com> wrote:
> Sparky wrote:
> > On Jul 12, 3:50 pm, Sparky <Samnspa... at gmail.com> wrote:
> >> Hello! I need to stream from a webcam in Linux and I need to be able
> >> to analyze the video feed frame by frame with PIL. Currently my web-
> >> cam (Quickcam Chat) only seems to work with GStreamer so a solution
> >> using pygst would be preferred.
>
> >> Thanks for your help,
> >> Sam
>
> > Sorry, to clarify I am just having a hard time capturing frames in a
> > way that I can access with PIL.
>
> Most web cams produce jpeg images so read the note at the bottom here;http://effbot.org/imagingbook/format-jpeg.htm
> What exactly are you trying to do? What have you tried so far and what
> happened may help.
>
> --
> Powered by Gentoo GNU/Linuxhttp://linuxcrazy.com
Dear David,
Thank you for your quick response. I have tried a few things. First of
all, I have tried gst-launch-0.10 v4l2src ! ffmpegcolorspace !
pngenc ! filesink location=foo.png. Foo.png comes out sharp enough but
it takes around 2 seconds to complete. I have also tried CVTypes but
it does not run without LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so and,
when it does run, it only displays colored "snow". Here is that code:
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(-1)
print "cam:" + str(camera)
def get_image():
print "here"
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()
im = get_image()
print im.mode
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))
Finally, I have gotten pygst to stream video with the example at
http://pygstdocs.berlios.de/pygst-tutorial/webcam-viewer.html but of
course I do not know how to get a hold of that data. Just so you know,
I am trying a primitive type of object tracking. I would use some of
the libraries already available but the two more popular
implementations on Linux (tbeta/ccv and reacTIVision) dont seem to
work with my web cam. I have more info on those non-python attempts at
http://ubuntuforums.org/showthread.php?p=7596908. Unfortunately no one
seemed to respond to that post.
Thanks again,
Sam
More information about the Python-list
mailing list