示例#1
0
 def reset(ctx: rs.ContextWrapper):
     """
     If there is no call for given seconds, removes the interlocutor node and initializes face oracle filter
     from scratch.
     """
     # Remove interloc if present
     if any(ctx.enum(interloc.prop_all)):
         popped_node = ctx.pop(
             f'interloc:all:{interloc.ANON_INTERLOC_ID}')
         if popped_node:
             logger.info(
                 "Visual contact is broken, removed the interlocutor node"
             )
     # Install a new FaceOracleFilter
     ctx[prop_face_filter] = FaceOracleFilter()
示例#2
0
 def am_i_bored_by_user(ctx: rs.ContextWrapper):
     """
     Emits idle:bored-by-user idle:bored as emitted and there is a present interlocutor.
     """
     if any(ctx.enum(interloc.prop_all)):
         return rs.Emit(wipe=True)
示例#3
0
 def is_busy(ctx: rs.ContextWrapper):
     busy = True if any(ctx.enum(interloc.prop_all)) else False
     # Set this as param if you want to use it inside ws_comm, otherwise you can just assign a variable
     if ROS_AVAILABLE:
         rospy.set_param('roboy_is_busy', busy)
示例#4
0
        def recognize_faces(ctx: rs.ContextWrapper):
            """
            Activates with each incoming face data served by face oracle. Responsible for synchronizing the node of
            person in vision with the anonymous interlocutor node. Uses face oracle filter to organize the incoming data
            and find out the right person.
            """

            face_filter: FaceOracleFilter = ctx[prop_face_filter]
            faces: Faces = ctx[prop_subscribe_faces]

            # Push faces to face filter
            best_guess_changed = face_filter.push_message(faces)
            if best_guess_changed:
                current_best_guess: Person = face_filter.current_best_guess

                onto: Ontology = mem.get_ontology()
                sess: Session = mem.get_session()

                person_node = Node(metatype=onto.get_type("Person"))

                best_guess_id = current_best_guess.id
                face_vector = current_best_guess.face_vector
                if current_best_guess.is_known:

                    person_node_query = sess.retrieve(node_id=best_guess_id)
                    if person_node_query:
                        person_node = person_node_query[0]
                    else:
                        err_msg = "Person with id %s is not found in memory." % best_guess_id
                        logger.error(err_msg)
                        return
                else:
                    person_node.set_properties({
                        'face_vector':
                        face_vector,
                        'name':
                        interloc.ANON_INTERLOC_ID
                    })

                push = False

                # Check if there is any interlocutor. If necessary and pop the current node and push person node
                # instead.
                if any(ctx.enum(interloc.prop_all)):
                    interloc_node: Node = ctx[
                        f'interloc:all:{interloc.ANON_INTERLOC_ID}']

                    # If interloc and the person nodes are not same pop and push person node.
                    if not (interloc_node.get_id() == person_node.get_id()
                            ) or interloc_node.get_id() < 0:
                        # Remove the current interloc
                        logger.info('Popping current interlocutor')
                        popped_node = ctx.pop(
                            f'interloc:all:{interloc.ANON_INTERLOC_ID}')
                        assert popped_node == True
                        push = True
                    else:
                        # Update the face vector of the person already familiar with
                        save_face(ctx, interloc_node.get_id(),
                                  current_best_guess.face_vector)
                else:
                    push = True
                if push:
                    # Push the new interlocutor
                    ctx.push(parent_property_or_path=interloc.prop_all,
                             child=rs.Property(name=interloc.ANON_INTERLOC_ID,
                                               default_value=person_node))
                    logger.info(
                        f"Pushed node with id {person_node.id} to interloc:all"
                    )