-
Notifications
You must be signed in to change notification settings - Fork 1
/
kinectdepthsrc.py
56 lines (41 loc) · 1.47 KB
/
kinectdepthsrc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
""" Source buf """
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
import gobject
#gobject.threads_init()
import pygst
pygst.require('0.10')
import gst
import numpy
import cv
import freenect
class KinectDepthSrc(gst.BaseSrc):
""" Depth """
#here we register our plugin details
__gstdetails__ = (
"Kinect depth source",
"kinectdepthsrc.py",
"Source element for Kinect depth",
"Oleksandr Lavrushchenko <[email protected]>")
_src_template = gst.PadTemplate ("src",
gst.PAD_SRC,
gst.PAD_ALWAYS,
gst.caps_from_string ("video/x-raw-gray,bpp=(int)16,depth=(int)16,width=[ 1, 2147483647 ],height=[ 1, 2147483647 ],framerate=[ 0/1, 2147483647/1 ]"))
__gsttemplates__ = (_src_template,)
def __init__ (self, *args, **kwargs):
gst.BaseSrc.__init__(self)
gst.info('creating srcpad')
self.src_pad = gst.Pad (self._src_template)
self.src_pad.use_fixed_caps()
def do_create(self, offset, length):
depth, timestamp = freenect.sync_get_depth()
databuf = numpy.getbuffer(depth)
self.buf = gst.Buffer(databuf)
self.buf.timestamp = 0
self.buf.duration = pow(2, 63) -1
return gst.FLOW_OK, self.buf
# Register element class
gobject.type_register(KinectDepthSrc)
gst.element_register(KinectDepthSrc, 'kinectdepthsrc', gst.RANK_MARGINAL)