public KinectManager(string modelData) { poseFinder.LoadCameraPoseFinderDatabase("poseFinder.txt"); FileStream stream = System.IO.File.OpenRead(modelData); // Open bracket char ch = (char) stream.ReadByte(); short[] modelVolumeData = new short[X_VOXELS * Y_VOXELS * Z_VOXELS]; StringBuilder b = new StringBuilder(); for (int i = 0; i < modelVolumeData.Length; i++) { ch = (char)stream.ReadByte(); while (ch != ']' && ch != ',') { b.Append(ch); ch = (char)stream.ReadByte(); } modelVolumeData[i] = short.Parse(b.ToString()); b.Clear(); if (i % 100000 == 0) { Console.WriteLine(i); } } /* string str = System.IO.File.ReadAllText(modelData).Trim(); str = str.Substring(1, str.Length - 2); string[] parts = str.Split(','); short[] modelVolumeData = new short[parts.Length]; for (int i = 0; i < parts.Length; i++) { modelVolumeData[i] = short.Parse(parts[i]); }*/ ReconstructionParameters rParams = new ReconstructionParameters(VOXEL_RESOLUTION, X_VOXELS, Y_VOXELS, Z_VOXELS); volume = ColorReconstruction.FusionCreateReconstruction(rParams, ReconstructionProcessor.Amp, -1, Matrix4.Identity); volume.ImportVolumeBlock(modelVolumeData); foreach (KinectSensor potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { sensor = potentialSensor; break; } } if (sensor == null) { Console.WriteLine("Can't find Kinect Sensor"); return; } sensor.DepthStream.Enable(DEPTH_FORMAT); sensor.ColorStream.Enable(COLOR_FORMAT); sensor.AllFramesReady += onFrameReady; sensor.Start(); }
private void loadAndStartDepth() { // Read in the model reconstruction (prescanned model) FileStream stream = System.IO.File.OpenRead(modelData); // Open bracket char ch = (char)stream.ReadByte(); // Copy all the model data into a short array of the same size short[] modelVolumeData = new short[X_VOXELS * Y_VOXELS * Z_VOXELS]; max = modelVolumeData.Length; // Parse what is essentially a really big json array StringBuilder b = new StringBuilder(); for (int i = 0; i < modelVolumeData.Length; i++) { ch = (char)stream.ReadByte(); while (ch != ']' && ch != ',') { b.Append(ch); ch = (char)stream.ReadByte(); } modelVolumeData[i] = short.Parse(b.ToString()); b.Clear(); progress = i; } // Build the reconstruction volume from the prescanned model // Now we have access to our prescanned model ReconstructionParameters rParams = new ReconstructionParameters(VOXEL_RESOLUTION, X_VOXELS, Y_VOXELS, Z_VOXELS); volume = ColorReconstruction.FusionCreateReconstruction(rParams, ReconstructionProcessor.Amp, -1, Matrix4.Identity); volume.ImportVolumeBlock(modelVolumeData); if (continuousTrack) { continueVolume = ColorReconstruction.FusionCreateReconstruction(rParams, ReconstructionProcessor.Amp, -1, Matrix4.Identity); } sensor.DepthStream.Enable(DEPTH_FORMAT); sensor.DepthFrameReady += depthFrameReady; isLoading = false; new Thread(new ThreadStart(runDepth)).Start(); }