示例#1
0
        private int calnFrame(ControlledHuman.Record record, int back = 0)
        {
            if (record.getIndex() < 1)
            {
                return(0);
            }
            X_POS currSpeed = record.getXSpeedSmooth(back);

            if (dtw[1] == 0f)
            {
                dtw[1] = X_POS.dtwDist(currSpeed, xSpeedSmooth[1]);
                return(1);
            }
            float[] nDtw = new float[timestamp.Count];

            if (circularDtw)
            {
                dtw[0] = dtw[timestamp.Count - 1];
            }

            for (int t = 1; t < timestamp.Count; t++)
            {
                if (nDtw[t - 1] != 0f && (nDtw[t] == 0f || nDtw[t - 1] < nDtw[t]))
                {
                    nDtw[t] = nDtw[t - 1];
                }
                if (dtw[t - 1] != 0f && (nDtw[t] == 0f || dtw[t - 1] < nDtw[t]))
                {
                    nDtw[t] = dtw[t - 1];
                }
                if (dtw[t] != 0f && (nDtw[t] == 0f || dtw[t] < nDtw[t]))
                {
                    nDtw[t] = dtw[t];
                }
                nDtw[t] += X_POS.dtwDist(currSpeed, xSpeedSmooth[t]);
            }
            dtw = nDtw;
            int frame = 1;

            for (int t = 2; t < timestamp.Count; t++)
            {
                if (dtw[t] != 0 && dtw[t] < dtw[frame])
                {
                    frame = t;
                }
            }
            return(frame);
        }
示例#2
0
        public float predictMotionFrame(ControlledHuman.Record record, out float score)
        {
            if (circularDtw)
            {
                circularCnt++;
                if (circularCnt >= timestamp.Count)
                {
                    int back = 50;
                    circularCnt = back;
                    dtw         = new float[timestamp.Count];
                    X_POS currSpeed = record.getXSpeedSmooth(back);
                    for (int t = 0; t < timestamp.Count; t++)
                    {
                        dtw[t] = X_POS.dtwDist(currSpeed, xSpeedSmooth[t]);
                    }
                    for (int i = back - 1; i >= 1; i--)
                    {
                        calnFrame(record, i);
                    }
                }
            }

            int dtwFrame = calnFrame(record);

            score         = dtw[dtwFrame];
            predictFrame += 1f;

            if (circularDtw)
            {
                float timeDist = dtwFrame - predictFrame;
                if (timeDist <= 0f)
                {
                    timeDist += timestamp.Count - 1f;
                }
                if (timeDist < (timestamp.Count - 1f) / 2f)
                {
                    predictFrame += 1.0f;
                }
                else
                {
                    predictFrame -= 0.5f;
                }
                if (predictFrame > timestamp.Count - 1f)
                {
                    predictFrame -= timestamp.Count - 1f;
                }
            }
            else
            {
                if (dtwFrame > predictFrame + 1.0f)
                {
                    predictFrame += 1.0f;
                }
                else if (dtwFrame < predictFrame - 0.5f)
                {
                    predictFrame -= 0.5f;
                }
                predictFrame = Mathf.Min(predictFrame, timestamp.Count - 1f);
            }
            return(predictFrame);
        }