/// <summary> /// Initializes a new instance of the MainWindow class. /// </summary> public MainWindow() { this.skelRec = new SkelRecorder(); this.skelDisp = new SkelDisplay(null); InitializeComponent(); // TODO: Delete this if (isTesting) { AnnTester.initNeuralNetworkTest(); } try { if (!isTesting) { if (isRecord) { Client.BeginReceive(new AsyncCallback(recv), null); } else { this.calibration = new Calibration(SESSION_TIMESTAMP, numOfCameras, this.skelDisp); } } } catch (Exception e) { Debug.WriteLine(e.ToString()); } }
/// <summary> /// Load the entire data of a single camera. /// </summary> /// <param name="cameraId"> Camera id of the camera whose file will be loaded </param> private void loadCameraFile(int cameraId) { string filename = null; BinaryReader reader = null; try { filename = SkelRecorder.getCameraFilename(_sessionTimestamp, cameraId); Console.Write("Loading camera file " + filename + "..."); reader = new BinaryReader(File.Open(filename, FileMode.Open)); int parsedCameraId = reader.ReadInt32(); if (cameraId != parsedCameraId) { throw new InvalidOperationException("Camera file #" + cameraId + " contains an illegal header: " + parsedCameraId); } try { // Read entire camera file to memory while (reader.BaseStream.Position != reader.BaseStream.Length) { SkelJointsData jointsData = fetchNextSkeletonFromCameraFile(reader, cameraId); _camRecordedFrames[cameraId].AddLast(jointsData); } } catch (System.IO.EndOfStreamException) { // This could happen if the recording crashed or a debug session was stopped ungracefully. // The recording could still be valid so don't crash, we try to replay what we can. Console.WriteLine("Warning: Recording ended unexpectedly."); } reader.Close(); reader.Dispose(); } catch (FileNotFoundException e) { Console.Error.Write("Error: Camera file " + filename + " not found"); Console.Error.Write("Details: " + e); Environment.Exit(1); } catch (IOException e) { Console.Error.Write("Error: IO Exception during openning of camera file " + filename); Console.Error.Write("Details: " + e); Environment.Exit(1); } }
/// <summary> /// Execute shutdown tasks /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e) { this.skelRec.closeFiles(); this.skelRec = null; }