コード例 #1
0
    void OnGUI()
    {
        if (train)
        {
            train_name = GUI.TextField(new Rect(25, 100, 100, 25), train_name);
            if (recording)
            {
                if (GUI.Button(new Rect(Screen.width - 150, 50, 100, 50), "Rec"))
                {
                    recorded_states.Add(new ArmsSnapshot(left_arm, right_arm));
                }

                if (GUI.Button(new Rect(25, 25, 100, 50), "Stop and Save"))
                {
                    RecordValues();
                    recording = false;
                }
                if (GUI.Button(new Rect(150, 25, 100, 50), "Stop (Don't Save)"))
                {
                    recording = false;
                }
            }
            else
            {
                if (GUI.Button(new Rect(25, 25, 100, 50), "Record"))
                {
                    recording = true;
                }
            }
            if (GUI.Button(new Rect(275, 25, 100, 50), "Stop Training"))
            {
                train = false;
            }
        }
        else
        {
            if (GUI.Button(new Rect(25, 25, 100, 50), "Train"))
            {
                train = true;
            }
            if (GUI.Button(new Rect(150, 25, 100, 50), "Update Library"))
            {
                ReadFile();
            }

            ArmsSnapshot cur_state = arm_states[arm_states.Count - 1];
            List <float> angles    = cur_state.GenerateAngles();
            string       line      = "";
            foreach (float angle in angles)
            {
                line += angle + " ";
            }
            GUI.Label(new Rect(50, Screen.height - 100, 200, 50), line);
            for (int i = 0; i < classifiers.Count; i++)
            {
                if (classifiers[i].GetProbablity(angles) > best_prob)
                {
                    identification = i;
                    best_data      = angles;
                    best_changed   = true;
                    best_prob      = classifiers[i].GetProbablity(angles);
                    best_name      = classifiers[i].pose_name;
                }


                string l = classifiers[i].pose_name + " " + classifiers[i].GetProbablity(angles);
                GUI.Label(new Rect(50, Screen.height - 150 - 50 * i, 200, 50), l);
            }
        }

        if (best_changed)
        {
            GUI.Label(new Rect(50, 200, 500, 50), "Best " + best_name + " is " + best_prob + ". Accept?");
            if (GUI.Button(new Rect(50, 250, 100, 25), "Accept"))
            {
                classifiers[identification].AddData(best_data);
                best_changed = false;
                RecordValues();
            }
            if (GUI.Button(new Rect(50, 250, 100, 25), "Reject"))
            {
                best_changed = false;
            }
            best_prob = 0;
        }
    }
コード例 #2
0
    void InterpretGestures()
    {
        //note: for the rush segments, we care more about current state
        //than changes in state, but other games will be slightly different
        //Debug.Log(arm_states.Count-1);


        if (arm_states.Count == 0)
        {
            return;
        }

        ArmsSnapshot cur_state = arm_states[arm_states.Count - 1];

        /*float left_out;
         * float right_out;
         * float arm_length = cur_state.GetLength();*/

        //order is hand, elbow, shoulder
        //we're going to generate angles on elbow joint and shoulder joint
        if (!train)
        {
            List <float> angles = cur_state.GenerateAngles();
            foreach (BayesianClassifier classifier in classifiers)
            {
                if (best < classifier.GetProbablity(angles))
                {
                    best = classifier.GetProbablity(angles);
                    Debug.Log(classifier.pose_name + " " + best);
                }

                //Debug.Log(classifier.pose_name + " " + classifier.GetProbablity(angles));
                if (classifier.GetProbablity(angles) > .001)
                {
                    Debug.Log("POSE DETECTED: " + classifier.pose_name);
                }
            }
        }



/*		//reset droplet movements
 *              droplet.back = droplet.left = droplet.right = droplet.up = droplet.down = 0f;
 *
 *              //left_out and right_out are going to be on a scale from 0 to 1
 *              //	0 all the way in, 1 all the way out
 *              left_out = (cur_state.left_joints[2].position.x - cur_state.left_joints[0].position.x)/arm_length;
 *              right_out = (cur_state.right_joints[0].position.x - cur_state.right_joints[2].position.x)/arm_length;
 *
 *
 *              //back, left, right
 *              //back - both hands forward
 *              if(left_out < 0.5 && right_out < 0.5){
 *                      droplet.back = 1 - (left_out + right_out)/2;
 *                      state = "stop";
 *              }
 *              //left - both arms out, left down, right up
 *              else if(cur_state.left_joints[0].position.y < cur_state.left_joints[2].position.y - 3*arm_length/4
 *                 && cur_state.right_joints[0].position.y > cur_state.right_joints[2].position.y - arm_length/4){
 *                      droplet.left = (cur_state.left_joints[2].position.y - cur_state.left_joints[0].position.y)/arm_length;
 *                      state = "left";
 *              }
 *              //right - both arms out, left up, right down
 *              else if(cur_state.left_joints[0].position.y > cur_state.left_joints[2].position.y - arm_length/4
 *                       && cur_state.right_joints[0].position.y < cur_state.right_joints[2].position.y - 3*arm_length/4){
 *                      droplet.right = (cur_state.right_joints[2].position.y - cur_state.right_joints[0].position.y)/arm_length;
 *                      state = "right";
 *              }
 *
 *              //INVERTED controls - up and down
 *              else if(cur_state.left_joints[0].position.y < cur_state.left_joints[2].position.y - 3*arm_length/4
 *                 && cur_state.right_joints[0].position.y < cur_state.right_joints[2].position.y - 3*arm_length/4){
 *                      //set their up movement based on extremity of their arm motion
 *                      float displacement = (cur_state.left_joints[2].position.y - cur_state.left_joints[0].position.y);
 *                      droplet.up = displacement/arm_length;
 *                      state = "up";
 *              }
 *
 *
 *              else if(cur_state.left_joints[0].position.y > cur_state.left_joints[2].position.y - arm_length/4
 *                 && cur_state.right_joints[0].position.y > cur_state.right_joints[2].position.y - arm_length/4){
 *                      float displacement = (cur_state.left_joints[0].position.y - cur_state.left_joints[2].position.y);
 *                      droplet.down = displacement/arm_length;
 *                      state = "down";
 *              }
 *              else
 *                      state = "none";
 *
 *              //RESET APPLICATION CONTROLS
 *              Vector3 arm = cur_state.right_joints[0].position - cur_state.right_joints[2].position;
 *              Vector3 down = new  Vector3(cur_state.right_joints[2].position.x,
 *                      cur_state.right_joints[2].position.y-1,
 *                      cur_state.right_joints[2].position.z) - cur_state.right_joints[2].position;
 *              Vector3 larm = cur_state.left_joints[0].position - cur_state.left_joints[2].position;
 *              Vector3 ldown = new  Vector3(cur_state.left_joints[2].position.x,
 *                      cur_state.left_joints[2].position.y-1,
 *                      cur_state.left_joints[2].position.z) - cur_state.left_joints[2].position;
 *
 *
 *              //get angle between the vectors
 *              float angle = Vector3.Angle(down, arm);
 *              //Debug.Log(right_out + " Angle is " + angle + " " + reset_timer + " " + Time.deltaTime);
 *              float langle = Vector3.Angle(ldown, larm);
 *
 *              //arm must be seventy percent extended and shoulder to hand is twenty to forty degrees from downwards
 *              if(right_out > .5 && (5 < angle && angle < 60) && langle < 15 ){
 *                      reset_timer += Time.deltaTime;
 *                      state = "reset";
 *              }
 *              else
 *                      reset_timer = 0f;
 *
 *
 *
 *
 *              //there is an arm forward and it is tilted skyward, go up
 *              if(left_out < 0.3f){
 *                      if(cur_state.left_joints[0].position.y > cur_state.left_joints[2].position.y)
 *                              droplet.up = 1f;
 *                      else if(cur_state.left_joints[0].position.y < cur_state.left_joints[2].position.y)
 *                              droplet.down = 1f;
 *              }
 *              //there is an arm forward and tilted down, go down
 *              else if(right_out < 0.3f){
 *                      if(cur_state.right_joints[0].position.y > cur_state.right_joints[2].position.y)
 *                              droplet.up = 1f;
 *                      else if(cur_state.right_joints[0].position.y < cur_state.right_joints[2].position.y)
 *                              droplet.down = 1f;
 *              }*/
    }
コード例 #3
0
    //we're going to look at the ways that the points are moving
    //and translate that into 5 directions (forward is controlled by the river)
    void InterpretGestures()
    {
        //note: for the rush segments, we care more about current state
        //than changes in state, but other games will be slightly different
        //Debug.Log(arm_states.Count-1);


        if (arm_states.Count == 0)
        {
            return;
        }

        ArmsSnapshot cur_state = arm_states[arm_states.Count - 1];
        float        left_out;
        float        right_out;
        float        arm_length = cur_state.GetLength();
        //look at just elbow length
        float _arm_length = (cur_state.left_joints[0].position - cur_state.left_joints[1].position).magnitude;

        //reset droplet movements
        droplet.back = droplet.left = droplet.right = droplet.up = droplet.down = 0f;

        //left_out and right_out are going to be on a scale from 0 to 1
        //	0 all the way in, 1 all the way out
        left_out  = (cur_state.left_joints[2].position.x - cur_state.left_joints[0].position.x) / arm_length;
        right_out = (cur_state.right_joints[0].position.x - cur_state.right_joints[2].position.x) / arm_length;


        //NEW METHOD - create idealized gestures and measure angle displacement from those
        Vector3 _left_diag_down = Quaternion.Euler(0, 0, 30) * new Vector3(-_arm_length, 0, 0);
        Vector3 _left_diag_up   = Quaternion.Euler(0, 0, -30) * new Vector3(-_arm_length, 0, 0);
        Vector3 _left_up        = Quaternion.Euler(0, 0, -45) * new Vector3(-_arm_length, 0, 0);
        Vector3 _left_down      = Quaternion.Euler(0, 0, 45) * new Vector3(-_arm_length, 0, 0);

        Vector3 _right_diag_down = Quaternion.Euler(0, 0, -30) * new Vector3(_arm_length, 0, 0);
        Vector3 _right_diag_up   = Quaternion.Euler(0, 0, 30) * new Vector3(_arm_length, 0, 0);
        Vector3 _right_up        = Quaternion.Euler(0, 0, 45) * new Vector3(_arm_length, 0, 0);
        Vector3 _right_down      = Quaternion.Euler(0, 0, -45) * new Vector3(_arm_length, 0, 0);

        Vector3 _hand_forward = new Vector3(0, 0, _arm_length);

        //current state vectors
        Vector3 _left_wing  = cur_state.left_joints[0].position - cur_state.left_joints[1].position;
        Vector3 _right_wing = cur_state.right_joints[0].position - cur_state.right_joints[1].position;


        //find displacements
        //back - both hands forward
        if (Mathf.Abs(Vector3.Angle(_hand_forward, _left_wing)) < 45 && Mathf.Abs(Vector3.Angle(_hand_forward, _right_wing)) < 45)
        {
            state = "stop";
        }
        //left - left diag down, right diag up
        else if (Mathf.Abs(Vector3.Angle(_left_diag_down, _left_wing)) < 45 && Mathf.Abs(Vector3.Angle(_right_diag_up, _right_wing)) < 45)
        {
            state = "left";
        }
        //right - left diag up, right diag down
        else if (Mathf.Abs(Vector3.Angle(_left_diag_up, _left_wing)) < 45 && Mathf.Abs(Vector3.Angle(_right_diag_down, _right_wing)) < 45)
        {
            state = "right";
        }
        //inverse controls - UP and DOWN
        else if (Mathf.Abs(Vector3.Angle(_left_up, _left_wing)) < 45 && Mathf.Abs(Vector3.Angle(_right_up, _right_wing)) < 45)
        {
            float displacement = (cur_state.left_joints[0].position.y - cur_state.left_joints[2].position.y);

            state = "down";
        }
        else if (Mathf.Abs(Vector3.Angle(_left_down, _left_wing)) < 45 && Mathf.Abs(Vector3.Angle(_right_down, _right_wing)) < 45)
        {
            //set their up movement based on extremity of their arm motion
            float displacement = (cur_state.left_joints[2].position.y - cur_state.left_joints[0].position.y);

            state = "up";
        }
        else
        {
            state = "none";
        }


        //RESET APPLICATION CONTROLS
        Vector3 arm  = cur_state.right_joints[0].position - cur_state.right_joints[2].position;
        Vector3 down = new  Vector3(cur_state.right_joints[2].position.x,
                                    cur_state.right_joints[2].position.y - 1,
                                    cur_state.right_joints[2].position.z) - cur_state.right_joints[2].position;
        Vector3 larm  = cur_state.left_joints[0].position - cur_state.left_joints[2].position;
        Vector3 ldown = new  Vector3(cur_state.left_joints[2].position.x,
                                     cur_state.left_joints[2].position.y - 1,
                                     cur_state.left_joints[2].position.z) - cur_state.left_joints[2].position;


        //get angle between the vectors
        float angle = Vector3.Angle(down, arm);
        //Debug.Log(right_out + " Angle is " + angle + " " + reset_timer + " " + Time.deltaTime);
        float langle = Vector3.Angle(ldown, larm);

        //arm must be seventy percent extended and shoulder to hand is twenty to forty degrees from downwards
        if (right_out > .5 && (5 < angle && angle < 60) && langle < 15)
        {
            reset_timer += Time.deltaTime;
            state        = "reset";
        }
        else
        {
            reset_timer = 0f;
        }
    }