private void OnRecordButton() { if (!m_isRecording) { if (!m_gestManager.m_skReader.IsSkeletonAvailable()) { m_showStr = "Please record after Kinect detects your skeleton"; } else { m_showStrHeader = "Recording..."; m_showStr = m_showStrHeader; m_skRecorder.Reset(); m_isRecording = true; } } else { if (!Directory.Exists(ConstDef.skelRootPath)) { Directory.CreateDirectory(ConstDef.skelRootPath); } string filename = m_inputStr; if (!filename.EndsWith(ConstDef.skelFileSuffix)) { filename += ConstDef.skelFileSuffix; } if (File.Exists(ConstDef.skelRootPath + filename)) { filename = "skeleton data " + DateTime.Now.ToString("yy-MM-dd-HH-mm-ss") + ConstDef.skelFileSuffix; } try { using (StreamWriter writer = new StreamWriter(ConstDef.skelRootPath + filename)) { m_skRecorder.SaveFile(writer); } m_showStr = "Skeleton data have been saved to " + filename; } catch (Exception e) { Debug.LogException(e); m_showStr = filename + ": error occurred when saving"; } m_isRecording = false; } ConstDef.defaultFileName = m_inputStr; }
public int LoadTrainConfigFile(StreamReader reader, string gestName) { string keyFrameFilename; int lastTotalLoaded = 0, totalLoaded = 0; m_skRecorder.Reset(); while (reader.Peek() > 0 && reader.ReadLine() != "@" + gestName) { ; } if (reader.Peek() <= 0) { throw new Exception("Gesture " + gestName + " not found in the train config file!"); } LoadJointIdx(reader.ReadLine()); LoadAlgorithmName(reader.ReadLine()); while (reader.Peek() > 0) { keyFrameFilename = reader.ReadLine(); if (keyFrameFilename == null || keyFrameFilename == "") { break; } if (!keyFrameFilename.EndsWith(ConstDef.KFFileSuffix)) { keyFrameFilename += ConstDef.KFFileSuffix; } try { using (StreamReader reader1 = new StreamReader(ConstDef.skelRootPath + keyFrameFilename)) { m_skRecorder.LoadFileAppend(reader1); totalLoaded = m_skRecorder.TaggedFrameCount; } m_eventStr += (totalLoaded - lastTotalLoaded) + " key frames loaded from " + keyFrameFilename + "\n"; lastTotalLoaded = totalLoaded; } catch (Exception e) { Debug.LogException(e); m_eventStr += keyFrameFilename + ": error occurred when loading file\n"; } } return(totalLoaded); }