/// <summary> /// Update kinect data in multithread /// </summary> private void UpdateKinectData() { bool _done = false; Chrono chrono = new Chrono(); chrono.Start(); double dt = 0.033; double next_schedule = 0.0; Debug.Log("Kinect acquisition started"); while (!_done) { double current_time = chrono.GetElapsedTime(); if (current_time > next_schedule) { next_schedule += dt; // Get depth map UpdateDepthData(); // Get color map UpdateColorData(); // Convert depth map into point cloud _cameraSpace = new CameraSpacePoint[_depthData.Length]; lock (_cameraSpace) { _mapper.MapDepthFrameToCameraSpace(_depthData, _cameraSpace); } // Map depth map to color map _colorSpace = new ColorSpacePoint[_depthData.Length]; lock (_colorSpace) { _mapper.MapDepthFrameToColorSpace(_depthData, _colorSpace); } } lock (doneLock) { _done = done; } Thread.Sleep(0); } Debug.Log("Kinect acquisition stopped"); }
private void UpdateKinectData() { bool _done = false; Capture _capture = null; Chrono chrono = new Chrono(); chrono.Start(); double dt; switch (kinectSensor.cameraFPS) { case FrameRate.Fifteen: dt = 1 / 15; break; case FrameRate.Thirty: dt = 1 / 30; break; case FrameRate.Five: dt = 1 / 5; break; default: dt = 1 / 60; // default unity fps break; } double next_schedule = 0.0; while (!_done) { double current_time = chrono.GetElapsedTime(); if (current_time > next_schedule) { next_schedule += dt; lock (capture) { if (isCaptureDirty) { _capture = capture; isCaptureDirty = false; } } if (_capture != null) { UpdateDepthData(_capture); UpdateColorData(_capture); _capture = null; } } lock (doneLock) { _done = done; } Thread.Sleep(0); } }