Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/plugins/camera_sensor/tacamera.py
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-11-20 14:30:09 (GMT)
committer Walter Bender <walter.bender@gmail.com>2011-11-20 14:30:09 (GMT)
commite8db7ac9313162d3a4da07ee525c60d40e744320 (patch)
tree094121ac5eff52d6d1f9dd5a12b8fe781bea43c8 /plugins/camera_sensor/tacamera.py
parent57dc446bbfd0719ab18364d862dcdacc3e843822 (diff)
capture directly to pixbuf
Diffstat (limited to 'plugins/camera_sensor/tacamera.py')
-rw-r--r--plugins/camera_sensor/tacamera.py43
1 files changed, 26 insertions, 17 deletions
diff --git a/plugins/camera_sensor/tacamera.py b/plugins/camera_sensor/tacamera.py
index 15824a1..72c1c69 100644
--- a/plugins/camera_sensor/tacamera.py
+++ b/plugins/camera_sensor/tacamera.py
@@ -21,33 +21,42 @@
#THE SOFTWARE.
import gst, time
+import gobject
-GST_PIPE = ['v4l2src', 'ffmpegcolorspace', 'pngenc']
-# GST_PIPE = ['v4l2src', 'ffmpegcolorspace', 'gdkpixbufsink']
+from TurtleArt.tautils import debug_output
+
+GST_PIPE = ['v4l2src', 'ffmpegcolorspace', 'gdkpixbufsink']
-class Camera():
- """ A class for representing the video camera """
- def __init__(self, imagepath):
- # self.imagepath = imagepath
- GST_PIPE.append('filesink location=%s' % imagepath)
- self.pipe = gst.parse_launch('!'.join(GST_PIPE))
- self.bus = self.pipe.get_bus()
- # self.bus.add_signal_watch()
- # self.bus.connect('message', self._on_message)
+class Camera():
+ ''' Sets up a pipe from the camera to a pixbuf and emits a signal
+ when the image is ready. '''
+
+ def __init__(self):
+ ''' Prepare camera pipeline to pixbuf and signal watch '''
+ self.pixbuf = None
+ self.pipe = gst.parse_launch('!'.join(GST_PIPE))
+ self.bus = self.pipe.get_bus()
+ self.bus.add_signal_watch()
+ self.bus.connect('message', self._on_message)
+ self.image_ready = False
def _on_message(self, bus, message):
''' We get a message if a pixbuf is available '''
if message.structure is not None:
- print message.structure.get_name()
+ # debug_output(message.structure.get_name(), True)
if message.structure.get_name() == 'pixbuf':
- message.structure['pixbuf'].save(self.imagepath, 'png')
+ self.pixbuf = message.structure['pixbuf']
+ self.bus.remove_signal_watch()
+ self.image_ready = True
- def save_camera_input_to_file(self):
- """ Grab a frame from the camera """
+ def start_camera_input(self):
+ ''' Start grabbing '''
self.pipe.set_state(gst.STATE_PLAYING)
- self.bus.poll(gst.MESSAGE_EOS, -1)
+ while not self.image_ready:
+ self.bus.poll(gst.MESSAGE_ANY, -1)
+ self.stop_camera_input()
def stop_camera_input(self):
+ ''' Stop grabbing '''
self.pipe.set_state(gst.STATE_NULL)
-