当前位置: 首页>>代码示例>>Python>>正文


Python OSCServer.delMsgHandler方法代码示例

本文整理汇总了Python中OSC.OSCServer.delMsgHandler方法的典型用法代码示例。如果您正苦于以下问题:Python OSCServer.delMsgHandler方法的具体用法?Python OSCServer.delMsgHandler怎么用?Python OSCServer.delMsgHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OSC.OSCServer的用法示例。


在下文中一共展示了OSCServer.delMsgHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Kinect

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import delMsgHandler [as 别名]
class Kinect(threading.Thread):
   def __init__(self, remote_ip = None):
      super(Kinect, self).__init__()

      core.register_terminate_func(self.close)

      # Synapse is running on a remote machine:
      if remote_ip:
         listen_ip = socket.gethostbyname(socket.gethostname())
         listen_port = 12345

         send_ip = remote_ip
         send_port = 12321

      # Synapse is running locally on this machine, using localhost
      else:
         listen_ip = 'localhost'
         listen_port = 12345

         send_ip = 'localhost'
         send_port = 12346

      self.server = OSCServer( (listen_ip, listen_port) )
      self.server.addMsgHandler( '/tracking_skeleton', self.callback_tracking_skeleton )
      self.server.addMsgHandler( 'default', self.callback_ignore )

      # create the client, which sends control messages to Synapse
      self.client = OSCClient()
      self.client.connect( (send_ip, send_port) )

      # member vars
      self.active_joints = {}
      self.last_heartbeat_time = 0
      self.done_running = False

      # start the server listening for messages
      self.start()

   # close must be called before app termination or the app might hang
   def close(self):
      # this is a workaround of a bug in the OSC server
      # we have to stop the thread first, make sure it is done,
      # and only then class server.close()
      self.server.running = False
      while not self.done_running:
         time.sleep(.01)
      self.server.close()

   def run(self):
      print "Worker thread entry point"
      self.server.serve_forever()
      self.done_running = True

   def add_joint(self, joint):
      self.server.addMsgHandler(joint + '_pos_body', self.callback)
      self.active_joints[joint] = np.array([0.0, 0.0, 0.0])

   def remove_joint(self, joint):
      self.server.delMsgHandler(joint + '_pos_body')
      del self.active_joints[joint]

   def on_update(self):
      now = time.time()
      send_heartbeat = now - self.last_heartbeat_time > 3.0
      if send_heartbeat:
         self.last_heartbeat_time = now

      try:
         for j in self.active_joints:
            if send_heartbeat:
               #print 'heartbeat:', j
               self.client.send( OSCMessage(j + "_trackjointpos", 1) )
      except Exception as x:
         print x, 'sending to', self.client.client_address

   def get_joint(self, joint) :
      return np.copy(self.active_joints[joint])

   def callback_ignore(self, path, tags, args, source):
      pass

   def callback(self, path, tags, args, source):
      #print path, args
      joint_name = path.replace("_pos_body", "")
      self.active_joints[joint_name] = np.array(args)

   def callback_tracking_skeleton(self, path, tags, args, source):
      pass
开发者ID:Vervious,项目名称:critters,代码行数:90,代码来源:kinect.py


注:本文中的OSC.OSCServer.delMsgHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。