def callback_user_pos(self, msg): """Handler for UserPos message. Head position """ self.userdata(msg.user_id, 'pos', msg) username = self.userdata(msg.user_id, 'username') # User recognition #if not username and self.trigger(msg.user_id): if not username: head_rect = get_rect_from_point( msg.head.position, MAX_HEAD_WIDTH, MAX_HEAD_HEIGHT ) try: start = now() self.recognize_user(msg.user_id, head_rect) rospy.loginfo("Time: %f", (now()-start).microseconds/1000000.0) except rospy.ServiceException, e: # If service goes off-line, shutdown and # wait until it comes back on-line. rospy.logwarn("Something went wrong with service call. Assuming it went offline.") self.sub.unregister() self.wait_for_service() return
def take_picture(self, data): rect = get_rect_from_point( data.head.position, MAX_HEAD_WIDTH, MAX_HEAD_HEIGHT ) self.args['pos'] = get_point(data.head.position) response = self.get_rect(*rect) (self.args['num'], self.args['file_path']) = self.save_img( response, '%s/img/%s' % ( self.package_path, self.args['username'] ), '%s_%s_%s' % ( self.args['test'], self.args['set'], self.args['label'] ) ) self.database.append(self.args) self._save_database() if self.args.has_key('value'): rospy.loginfo("Saved %s" % str(self.args['value'])) else: rospy.loginfo("Saved")
def callback_add_object(self, request): user_pos = self.userdata(request.user_id, 'pos') success = False if user_pos: rect = get_rect_from_point( user_pos.left_arm.hand.position, MAX_HEAD_WIDTH, MAX_HEAD_HEIGHT ) try: insert_topic = rospy.ServiceProxy('/recognize/objects/insert_topic', InsertTopic) response = insert_topic(request.username, *rect) success = response.success except rospy.ServiceException, e: rospy.logerr("Service call failed: %s" % e) success = False
def callback_add_user(self, request): """ Callback to add user to face recognition database. Keyword arguments: request.user_id -- Id of the user to add request.username -- Username or label for face. """ user_pos = self.userdata(request.user_id, 'pos') success = False if user_pos: rect = get_rect_from_point( user_pos.head.position, MAX_HEAD_WIDTH, MAX_HEAD_HEIGHT ) try: insert_topic = rospy.ServiceProxy('/recognize/users/insert_topic', InsertTopic) response = insert_topic(request.username, *rect) success = response.success except rospy.ServiceException, e: rospy.logerr("Service call failed: %s" % e) success = False