Пример #1
0
    public CalibrationData calibrate()
    {
        Vector3        avg  = Vector3.zero;
        MinMax3        mmm  = MinMax3.Create();
        List <Vector3> data = new List <Vector3>(size);

        foreach (Vector3 v in readings.getValues())
        {
            data.Add(v);
        }
        data.Sort((a, b) => { return(a.sqrMagnitude.CompareTo(b.sqrMagnitude)); });

        //average & minMax
        int     samples  = (int)(data.Count * 0.88f);
        Vector3 deviaton = Vector3.zero;

        for (int i = 0; i < samples; ++i)
        {
            mmm.add(data[i]);
            avg += data[i];
        }
        avg /= samples;

        //standard deviation
        for (int i = 0; i < samples; ++i)
        {
            deviaton += (data[i] - avg).componentsSquared();
        }
        deviaton = (deviaton / samples).componentsSqrt();

        //runs
        Run[] avgRuns = runBuffer3.averageRuns();
        Run[] runStandardDeviations = runBuffer3.standardDeviation(avgRuns);

        CalibrationData cd = new CalibrationData()
        {
            average = avg, minMax3 = mmm, standardDeviation = deviaton, averageRuns = avgRuns, runSDS = runStandardDeviations
        };

        Debug.Log(cd.ToString());
        EditorApplication.isPaused = true;
        return(cd);
    }
Пример #2
0
    void Update()
    {
        kinectData = KinectData.GetComponent <KinectController>();

        Kinect.Body closestBody = GetClosestBody();

        if (closestBody == null)
        {
            ResetCalibration(null, "body not found");
            return;
        }

        ulong currentClosestTrackingId = closestBody.TrackingId;

        if (trackingId != currentClosestTrackingId)
        {
            ResetCalibration(currentClosestTrackingId, "body not found");
            return;
        }

        Kinect.Body currentBody = kinectData.Bodies.Find(body => body.TrackingId == trackingId);

        if (calibrationTimer < calibrationTime)
        {
            shoulderAndHipRatio.AddData(GetShoulderAndHipRatio(
                                            GetBodyPosition(currentBody, Kinect.JointType.ShoulderLeft),
                                            GetBodyPosition(currentBody, Kinect.JointType.ShoulderRight),
                                            GetBodyPosition(currentBody, Kinect.JointType.HipLeft),
                                            GetBodyPosition(currentBody, Kinect.JointType.HipRight)));

            upperbodyLength.AddData(GetUpperbodyLength(
                                        GetBodyPosition(currentBody, Kinect.JointType.Head),
                                        GetBodyPosition(currentBody, Kinect.JointType.Neck),
                                        GetBodyPosition(currentBody, Kinect.JointType.SpineBase)));

            DisplayText.text = string.Format("Time: {2}\n\nSH: {0}\nUL: {1}",
                                             shoulderAndHipRatio.ToString(),
                                             upperbodyLength.ToString(),
                                             calibrationTimer.ToString("0.00"));

            calibrationTimer += Time.deltaTime;
        }
        else
        {
            if (Application.loadedLevelName == "MainMenu" || Application.loadedLevel == 0)
            {
                SetPlayerPrefs(trackingId.Value, shoulderAndHipRatio.Average, upperbodyLength.Average);
                Application.LoadLevel(1); // change this later
            }
            else
            {
                if (Match(shoulderAndHipRatio.Average, upperbodyLength.Average))
                {
                    Application.LoadLevel(Application.loadedLevel);
                }
                else
                {
                    ResetCalibration(null, "not a match");
                }
            }
        }
    }