Skip to content

Instantly share code, notes, and snippets.

@tito
Created October 26, 2012 22:42
Show Gist options
  • Save tito/3961987 to your computer and use it in GitHub Desktop.
Save tito/3961987 to your computer and use it in GitHub Desktop.
'''
Liste des joints
================
- l/r shoulder: epaule
- l/r elbow: genou
- l/r foot: pieds
- l/r knee: genou
- l/r hip: hanche
- head: tete
- neck: cou
- l/r hand: mains
- torso: torse
'''
import kivy
kivy.require('1.4.1')
from kivy.app import App
from kivy.uix.widget import Widget
'''
Liste des joints
================
- l/r shoulder: epaule
- l/r elbow: genou
- l/r foot: pieds
- l/r knee: genou
- l/r hip: hanche
- head: tete
- neck: cou
- l/r hand: mains
- torso: torse
'''
import kivy
kivy.require('1.4.1')
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ListProperty, DictProperty
from kivy.lib import osc
from kivy.lang import Builder
from kivy.clock import Clock
Builder.load_string('''
<Body>:
size_hint: None, None
canvas:
Color:
rgb: 1, 1, 0
Line:
circle: self.head[0], self.head[1], 10 + self.head[2] * 10
''')
class Body(Widget):
l_shoulder = ListProperty([0, 0, 0])
r_shoulder = ListProperty([0, 0, 0])
l_elbow = ListProperty([0, 0, 0])
r_elbow = ListProperty([0, 0, 0])
l_foot = ListProperty([0, 0, 0])
r_foot = ListProperty([0, 0, 0])
l_knee = ListProperty([0, 0, 0])
r_knee = ListProperty([0, 0, 0])
torso = ListProperty([0, 0, 0])
l_hand = ListProperty([0, 0, 0])
r_hand = ListProperty([0, 0, 0])
head = ListProperty([0, 0, 0])
neck = ListProperty([0, 0, 0])
class BodyKinectApp(App):
users = DictProperty({})
def build(self):
self.start_osc()
return FloatLayout()
def start_osc(self):
self.oscid = osc.listen('127.0.0.1', 7110)
osc.bind(self.oscid, self.callback_osc, '/new_user')
osc.bind(self.oscid, self.callback_osc, '/new_skel')
osc.bind(self.oscid, self.callback_osc, '/lost_user')
osc.bind(self.oscid, self.callback_osc, '/joint')
osc.bind(self.oscid, self.callback_osc, '/user')
Clock.schedule_interval(self.update_osc, 1 / 60.)
def update_osc(self, dt):
osc.readQueue(self.oscid)
def callback_osc(self, message, *largs):
action, fmt = message[:2]
if action == '/joint':
joint = message[2]
userid = message[3]
x, y, z = message[4:7]
if userid not in self.users:
# auto recreation of the user
self.users[userid] = body = Body()
self.root.add_widget(body)
osc.bind(self.oscid, self.callback_osc, '/user/{0}'.format(userid))
setattr(self.users[userid], joint,
(x * self.root.width, self.root.height - y * self.root.height, z))
elif action == '/new_user':
userid = message[2]
self.users[userid] = body = Body()
self.root.add_widget(body)
osc.bind(self.oscid, self.callback_osc, '/user/{0}'.format(userid))
elif action == '/lost_user':
userid = message[2]
body = self.users.pop(userid)
self.root.remove_widget(body)
osc.unbind(self.oscid, self.callback_osc, '/user/{0}'.format(userid))
if __name__ == '__main__':
BodyKinectApp().run()
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ListProperty, DictProperty
from kivy.lib import osc
from kivy.lang import Builder
from kivy.clock import Clock
Builder.load_string('''
<Body>:
size_hint: None, None
canvas:
Color:
rgb: 1, 1, 0
Line:
circle: self.head[0], self.head[1], 10 + self.head[2] * 10
''')
class Body(Widget):
l_shoulder = ListProperty([0, 0, 0])
r_shoulder = ListProperty([0, 0, 0])
l_elbow = ListProperty([0, 0, 0])
r_elbow = ListProperty([0, 0, 0])
l_foot = ListProperty([0, 0, 0])
r_foot = ListProperty([0, 0, 0])
l_knee = ListProperty([0, 0, 0])
r_knee = ListProperty([0, 0, 0])
torso = ListProperty([0, 0, 0])
l_hand = ListProperty([0, 0, 0])
r_hand = ListProperty([0, 0, 0])
head = ListProperty([0, 0, 0])
neck = ListProperty([0, 0, 0])
def on_head(self, instance, value):
print 'VALUE', value
class BodyKinectApp(App):
users = DictProperty({})
def build(self):
self.start_osc()
return FloatLayout()
def start_osc(self):
self.oscid = osc.listen('127.0.0.1', 7110)
osc.bind(self.oscid, self.callback_osc, '/new_user')
osc.bind(self.oscid, self.callback_osc, '/new_skel')
osc.bind(self.oscid, self.callback_osc, '/lost_user')
osc.bind(self.oscid, self.callback_osc, '/joint')
osc.bind(self.oscid, self.callback_osc, '/user')
Clock.schedule_interval(self.update_osc, 1 / 60.)
def update_osc(self, dt):
osc.readQueue(self.oscid)
def callback_osc(self, message, *largs):
print 'callback', message
action, fmt = message[:2]
if action == '/joint':
joint = message[2]
userid = message[3]
x, y, z = message[4:7]
if userid not in self.users:
return
print self.users[userid]
#setattr(self.users[userid], joint,
# (x * self.root.width, y * self.root.height, z))
elif action == '/new_user':
userid = message[2]
self.user[userid] = body = Body()
self.root.add_widget(body)
print "BIND", '/user/{0}'.format(userid)
osc.bind(self.oscid, self.callback_osc, '/user/{0}'.format(userid))
elif action == '/lost_user':
userid = message[2]
body = self.user.pop(userid)
self.root.remove_widget(body)
osc.unbind(self.oscid, self.callback_osc, '/user/{0}'.format(userid))
if __name__ == '__main__':
BodyKinectApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment