예제 #1
0
    public void OnTrainButton()
    {
        if (m_skRecorder.TaggedFrameCount == 0)
        {
            m_showStr = "Please load skeleton data with key frames before training.";
            return;
        }

        GestureDetector gestDet = m_tpTrainer.Train(m_inputStr);

        if (!Directory.Exists(ConstDef.tmplRootPath))
        {
            Directory.CreateDirectory(ConstDef.tmplRootPath);
        }
        string filename = m_inputStr;

        if (!filename.EndsWith(ConstDef.tmplFileSuffix))
        {
            filename += ConstDef.tmplFileSuffix;
        }
        if (!m_isOverride && File.Exists(ConstDef.tmplRootPath + filename))
        {
            filename = "gesture template " + DateTime.Now.ToString("yy-MM-dd-HH-mm-ss") + ConstDef.tmplFileSuffix;
        }
        string strOverride = (m_isOverride && File.Exists(ConstDef.tmplRootPath + filename)) ? "overwritten" : "saved";

        try
        {
            using (StreamWriter writer = new StreamWriter(ConstDef.tmplRootPath + filename, false))
            {
                gestDet.SaveToFile(writer);
                m_showStr = "The gesture template has been trained and " + strOverride + " to " + filename;
            }
        }
        catch (Exception e)
        {
            Debug.LogException(e);
            m_showStr = filename + ": error occurred when saving template";
        }

        ConstDef.defaultFileName = m_inputStr;
    }