示例#1
0
    public void contrast(List <List <float> > sequence)
    {
        List <List <List <float> > > fingers        = new List <List <List <float> > >();
        List <List <List <float> > > spins          = new List <List <List <float> > >();
        List <List <List <float> > > rolls          = new List <List <List <float> > >();
        List <List <List <float> > > fingers_sample = new List <List <List <float> > >();
        List <List <List <float> > > spins_sample   = new List <List <List <float> > >();
        List <List <List <float> > > rolls_sample   = new List <List <List <float> > >();

        for (int i = 0; i < 5; i++)
        {
            fingers.Add(new List <List <float> >());
            spins.Add(new List <List <float> >());
            rolls.Add(new List <List <float> >());
            fingers_sample.Add(new List <List <float> >());
            spins_sample.Add(new List <List <float> >());
            rolls_sample.Add(new List <List <float> >());
        }

        for (int i = 0; i < sequence.Count; i++)
        {
            List <float> temp = sequence[i];
            for (int j = 0; j < temp.Count; j++)
            {
                for (int k = 0; k < 5; k++)
                {
                    List <float> finger = new List <float>();
                    List <float> spin   = new List <float>();
                    List <float> roll   = new List <float>();
                    float        x      = temp[3 * k] * Mathf.PI / 180;
                    float        y      = temp[3 * k + 1] * Mathf.PI / 180;
                    float        z      = temp[3 * k + 2];
                    finger.Add(Mathf.Cos(x) * Mathf.Cos(y));
                    finger.Add(Mathf.Sin(x) * Mathf.Cos(y));
                    finger.Add(Mathf.Sin(y));
                    spin.Add(z);
                    roll.Add(temp[15 + k]);
                    fingers[k].Add(finger);
                    spins[k].Add(spin);
                    rolls[k].Add(roll);
                }
            }
        }
        for (int fileNumber = 0; fileNumber < 4; fileNumber++)
        {
            string[] strs = File.ReadAllLines(@"C:\Users\27586\PycharmProjects\HCI\HCI-Project\origin\data\hou-data" + (fileNumber + 1) + "-1.txt");
            for (int i = 0; i < strs.Length; i++)
            {
                string[] str = Regex.Split(strs[i], ",", RegexOptions.IgnoreCase);
                for (int j = 0; j < 5; j++)
                {
                    List <float> finger = new List <float>();
                    List <float> spin   = new List <float>();
                    List <float> roll   = new List <float>();
                    float        x      = float.Parse(str[3 * j + 1]) * Mathf.PI / 180;
                    float        y      = float.Parse(str[3 * j + 2]) * Mathf.PI / 180;
                    float        z      = float.Parse(str[3 * j + 3]);
                    finger.Add(Mathf.Cos(x) * Mathf.Cos(y));
                    finger.Add(Mathf.Sin(x) * Mathf.Cos(y));
                    finger.Add(Mathf.Sin(y));
                    spin.Add(z);
                    roll.Add(float.Parse(str[16 + j]));
                    fingers_sample[j].Add(finger);
                    spins_sample[j].Add(spin);
                    rolls_sample[j].Add(roll);
                }
            }
            float score = 0;
            for (int i = 0; i < 5; i++)
            {
                score = score + 1.8f * Contrast.DTW(fingers[i], fingers_sample[i]) / 180 + 0.3f * Contrast.DTW(spins[i], spins_sample[i]) / 180 + 0.9f * Contrast.DTW(rolls[i], rolls_sample[i]) / 200;
            }
            Debug.Log((fileNumber + 1) + ":" + score);
            if (score < 1.4)
            {
                score = 1.4f;
            }
            if (score > 3.4)
            {
                score = 3.4f;
            }
            simi[fileNumber] = (3.4f - score) * 50;
            sequence.Clear();
            for (int i = 0; i < 5; i++)
            {
                fingers_sample[i] = new List <List <float> >();
                spins_sample[i]   = new List <List <float> >();
                rolls_sample[i]   = new List <List <float> >();
            }
        }
        if (Mathf.Max(simi[0], simi[1], simi[2], simi[3]) > 90)
        {
            result = 1;
        }
        else
        {
            result = 2;
        }
    }
示例#2
0
    public void contrast(List <List <float> > sequence)
    {
        List <List <List <float> > > fingers        = new List <List <List <float> > >();
        List <List <List <float> > > spins          = new List <List <List <float> > >();
        List <List <List <float> > > rolls          = new List <List <List <float> > >();
        List <List <List <float> > > fingers_sample = new List <List <List <float> > >();
        List <List <List <float> > > spins_sample   = new List <List <List <float> > >();
        List <List <List <float> > > rolls_sample   = new List <List <List <float> > >();

        for (int i = 0; i < 5; i++)
        {
            fingers.Add(new List <List <float> >());
            spins.Add(new List <List <float> >());
            rolls.Add(new List <List <float> >());
            fingers_sample.Add(new List <List <float> >());
            spins_sample.Add(new List <List <float> >());
            rolls_sample.Add(new List <List <float> >());
        }

        for (int i = 0; i < sequence.Count; i++)
        {
            List <float> temp = sequence[i];
            for (int j = 0; j < temp.Count; j++)
            {
                for (int k = 0; k < 5; k++)
                {
                    List <float> finger = new List <float>();
                    List <float> spin   = new List <float>();
                    List <float> roll   = new List <float>();
                    float        x      = temp[3 * k] * Mathf.PI / 180;
                    float        y      = temp[3 * k + 1] * Mathf.PI / 180;
                    float        z      = temp[3 * k + 2];
                    finger.Add(Mathf.Cos(x) * Mathf.Cos(y));
                    finger.Add(Mathf.Sin(x) * Mathf.Cos(y));
                    finger.Add(Mathf.Sin(y));
                    spin.Add(z);
                    roll.Add(temp[15 + k]);
                    fingers[k].Add(finger);
                    spins[k].Add(spin);
                    rolls[k].Add(roll);
                }
            }
        }

        string[] strs = File.ReadAllLines(@"C:\Users\27586\PycharmProjects\HCI\HCI-Project\origin\data\hou-data" + Selection.GetChoose() + "-1.txt");
        for (int i = 0; i < strs.Length; i++)
        {
            string[] str = Regex.Split(strs[i], ",", RegexOptions.IgnoreCase);
            for (int j = 0; j < 5; j++)
            {
                List <float> finger = new List <float>();
                List <float> spin   = new List <float>();
                List <float> roll   = new List <float>();
                float        x      = float.Parse(str[3 * j + 1]) * Mathf.PI / 180;
                float        y      = float.Parse(str[3 * j + 2]) * Mathf.PI / 180;
                float        z      = float.Parse(str[3 * j + 3]);
                finger.Add(Mathf.Cos(x) * Mathf.Cos(y));
                finger.Add(Mathf.Sin(x) * Mathf.Cos(y));
                finger.Add(Mathf.Sin(y));
                spin.Add(z);
                roll.Add(float.Parse(str[16 + j]));
                fingers_sample[j].Add(finger);
                spins_sample[j].Add(spin);
                rolls_sample[j].Add(roll);
            }
        }
        float score = 0;

        for (int i = 0; i < 5; i++)
        {
            score = score + 1.8f * Contrast.DTW(fingers[i], fingers_sample[i]) / 180 + 0.3f * Contrast.DTW(spins[i], spins_sample[i]) / 180 + 0.9f * Contrast.DTW(rolls[i], rolls_sample[i]) / 200;
        }
        Debug.Log(score);
        if (score < 1.5)
        {
            result    = 1;
            isSuccess = true;
        }
        else
        {
            result   = 2;
            isFailed = true;
        }
        sequence.Clear();
    }