コード例 #1
0
    public bool recognizeSequence(ActionInstance inst)
    {
        if (_isProcessing)
        {
            return(false);
        }

        StopCoroutine("CheckThreadsCoroutine");

        _isProcessing = true;
        List <ActionData> actions = ActionDatabase.instance.actionsData;

        foreach (ActionData d in actions)
        {
            RecognitionThread w = new RecognitionThread(inst, d, stepConstraints);
            Thread            t = new Thread(new ThreadStart(w.process));
            _recognitionThreads.Add(t);
            _recognitionWorkers.Add(w);
            t.Start();
        }

        StartCoroutine(CheckThreadsCoroutine());

        return(true);
    }
コード例 #2
0
    IEnumerator CheckThreadsCoroutine()
    {
        while (_isProcessing)
        {
            yield return(new WaitForSeconds(1.0f));

            int idx = 0;
            foreach (RecognitionThread t in _recognitionWorkers)
            {
                if (t.isDone)
                {
                    idx++;
                }
            }

            // if all threads are done
            if (idx == _recognitionWorkers.Count)
            {
                print("-- all done");

                float             mincost = float.PositiveInfinity;
                ActionData        mindata = null;
                RecognitionThread minwork = null;
                foreach (RecognitionThread t in _recognitionWorkers)
                {
                    float cost = t.dtw.getWarpPathCost();
                    if (cost < mincost)
                    {
                        mincost = cost;
                        mindata = t._subseq;
                        minwork = t;
                    }
                }

                Texture2D tmpT = mDebug.drawMatrix(minwork.dtw.CostMatrix);
                tmpT = mDebug.drawPoints(tmpT, minwork.warppath.ToArray(), Color.red);
//				tmpT = mDebug.drawPoints(tmpT, new mIndex[] {minwork.warppath[0]}, Color.red);
//				tmpT = mDebug.drawPoints(tmpT, new mIndex[] {minwork.warppath[minwork.warppath.Count-1]}, Color.red);

                costMatrixTexture.texture = tmpT;
                costMatrixTexture.transform.localScale = new Vector3(0.2f, 0.2f * ((float)minwork.dtw.AccumCostMatrix.Length / (float)minwork.dtw.AccumCostMatrix[0].Length), 1);
                costMatrixTexture.transform.position   = new Vector3(0.5f * costMatrixTexture.transform.localScale.x, costMatrixTexture.transform.localScale.y, 0);

//				mDebug.printMatrix(minwork.dtw.CostMatrix);
//				mDebug.printMatrix(minwork.dtw.AccumCostMatrix);

                OnRecognitionDone(minwork._subseq, minwork._seq, minwork.dtw);

                foreach (Thread t in _recognitionThreads)
                {
                    t.Abort();
                }
                _recognitionThreads.Clear();
                _recognitionWorkers.Clear();
                _isProcessing = false;
            }
        }
    }
コード例 #3
0
    public bool recognizeSequence(ActionInstance inst)
    {
        if (_isProcessing)	return false;

        StopCoroutine("CheckThreadsCoroutine");

        _isProcessing = true;
        List<ActionData> actions = ActionDatabase.instance.actionsData;
        foreach(ActionData d in actions)
        {
            RecognitionThread w = new RecognitionThread(inst, d, stepConstraints);
            Thread t = new Thread(new ThreadStart(w.process));
            _recognitionThreads.Add(t);
            _recognitionWorkers.Add(w);
            t.Start();
        }

        StartCoroutine(CheckThreadsCoroutine());

        return true;
    }