GStreamer + Python + The Imaging Source Camera
Primoz
pzufic at mail.com
Mon Jun 22 01:01:38 PDT 2015
Hello!
I'm new to GStreamer and I want to get single images from The Imaging Source
USB Camera.
I'm using the code below. The problem is that I can get images from camera
without using self.appsink.connect("new-buffer", self.on_new_buffer), but
some of that images are corrupted in the way that there are multiple parts
of image glued together. My assumption is that this is caused by reading and
writing the buffer at the same time. So that's why I update the code to read
the buffer only when there is new one. The problem is that it never gets
into the on_new_buffer function.
Where can it be the problem?
import pygst
pygst.require("0.10")
import gst
import pygtk
#import gtk
import sys
import numpy
class TIS:
'The Imaging Source Camera'
import gobject
gobject.threads_init()
def __init__(self, w, h, fps):
self.w = w
self.h = h
self.fps = fps
self.slika = numpy.empty(shape=(self.h,self.w,1),dtype='uint8')
self.pipeline = gst.Pipeline("mypipeline")
self.v4l2src = gst.element_factory_make("v4l2src", "v4l2")
self.pipeline.add(self.v4l2src)
def Create_pipeline(self):
parameter1 = 'video/x-raw-gray,width=' + str(self.w) + ',height=' +
str(self.h) + ',framerate=' + str(self.fps) + '/1'
self.caps = gst.Caps("%s" % parameter1)
self.capsFilter = gst.element_factory_make("capsfilter")
self.capsFilter.set_property("caps",self.caps)
self.pipeline.add(self.capsFilter)
self.tisvideobufferfilter =
gst.element_factory_make("tisvideobufferfilter","videobuffer")
self.pipeline.add(self.tisvideobufferfilter)
self.ffmpegcolorspace =
gst.element_factory_make("ffmpegcolorspace","colorspace")
self.pipeline.add(self.ffmpegcolorspace)
self.appsink = gst.element_factory_make("appsink","sink")
self.appsink.set_property("max-buffers",2)
self.appsink.set_property("emit-signals", True)
self.appsink.connect("new-buffer", self.on_new_buffer)
self.pipeline.add(self.appsink)
self.v4l2src.link(self.capsFilter)
self.capsFilter.link(self.tisvideobufferfilter)
self.tisvideobufferfilter.link(self.ffmpegcolorspace)
self.ffmpegcolorspace.link(self.appsink)
def Get_image(self):
self.pipeline.set_state(gst.STATE_PLAYING)
def on_new_buffer(self):
print "on_new_buffer"
self.sample = self.appsink.emit('pull-buffer')
self.slika =
numpy.ndarray(shape=(self.h,self.w,1),dtype='uint8',buffer=self.sample.data)
self.pipeline.set_state(gst.STATE_PAUSED)
def Stop_pipeline(self):
self.pipeline.set_state(gst.STATE_PAUSED)
self.pipeline.set_state(gst.STATE_READY)
self.pipeline.set_state(gst.STATE_NULL)
--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/GStreamer-Python-The-Imaging-Source-Camera-tp4672373.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
More information about the gstreamer-devel
mailing list