Exemple #1
0
        /// <summary>
        /// Records a new .xef file
        /// </summary>
        /// <param name="filePath">Full path to where the file should be saved to</param>
        private void RecordClip(string filePath)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                // Specify which streams should be recorded
                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
                streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Body);
                streamCollection.Add(KStudioEventStreamDataTypeIds.BodyIndex);

                // Create the recording object
                using (KStudioRecording recording = client.CreateRecording(filePath, streamCollection))
                {
                    recording.StartTimed(this.duration);
                    while (recording.State == KStudioRecordingState.Recording)
                    {
                        Thread.Sleep(500);
                    }
                }

                client.DisconnectFromService();
            }

            // Update UI after the background recording task has completed
            this.isRecording = false;
            this.Dispatcher.BeginInvoke(new NoArgDelegate(UpdateState));
        }
        /// <summary>
        /// Function used to store raw data from kinect
        /// </summary>
        /// <param name="filePath">path of the recording file</param>
        /// <param name="duration">duration of the recording in seconds</param>
        public void RecordData(string filePath, TimeSpan duration)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
                streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Body);

                using (KStudioRecording recording = client.CreateRecording(filePath, streamCollection))
                {
                    recording.StartTimed(duration);
                    while (recording.State == KStudioRecordingState.Recording)
                    {
                        Thread.Sleep(500);
                    }

                    if (recording.State == KStudioRecordingState.Error)
                    {
                        throw new InvalidOperationException("Error: Recording failed!");
                    }
                }

                client.DisconnectFromService();
            }
        }
        public Task RecordClip(string filePath, TimeSpan duration)
        {
            if (IsRecording || IsPlaying)
            {
                return(null);
            }

            if (duration == TimeSpan.Zero)
            {
                duration = _maxRecordingDuration;
            }

            _stopRequested = false;
            Task t = Task.Run(() =>
            {
                _recording = true;
                using (KStudioClient client = KStudio.CreateClient())
                {
                    client.ConnectToService();

                    KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
                    //streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
                    streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
                    streamCollection.Add(KStudioEventStreamDataTypeIds.Body);
                    streamCollection.Add(KStudioEventStreamDataTypeIds.BodyIndex);
                    streamCollection.Add(KStudioEventStreamDataTypeIds.UncompressedColor);

                    using (KStudioRecording recording = client.CreateRecording(filePath, streamCollection))
                    {
                        recording.StartTimed(duration);
                        while (recording.State == KStudioRecordingState.Recording)
                        {
                            if (_stopRequested)
                            {
                                recording.Stop();
                            }
                            Thread.Sleep(50);
                        }

                        if (recording.State == KStudioRecordingState.Error)
                        {
                            throw new InvalidOperationException("Error: Recording failed!");
                        }
                    }

                    client.DisconnectFromService();
                }
                Thread.Sleep(500);
                _recording = false;
            });

            return(t);
        }
Exemple #4
0
        /// <summary>
        /// Records a new .xef file and saves body data to a .txt file
        /// </summary>
        /// <param name="filePath">full path to where the file should be saved to</param>
        private void RecordClip(string filePath)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection
                {
                    KStudioEventStreamDataTypeIds.Ir,
                    KStudioEventStreamDataTypeIds.Depth,
                    KStudioEventStreamDataTypeIds.Body,
                    KStudioEventStreamDataTypeIds.BodyIndex,
                    KStudioEventStreamDataTypeIds.UncompressedColor
                };

                using (KStudioRecording recording = client.CreateRecording(filePath, streamCollection))
                {
                    recording.StartTimed(this.duration);
                    while (recording.State == KStudioRecordingState.Recording)
                    {
                        Thread.Sleep(500);
                    }
                }

                client.DisconnectFromService();
            }

            if (this.trackedBodies.Count > 0)
            {
                this.SaveBodiesToFile(this.trackedBodies);
            }

            // Update UI after the background recording task has completed
            this.isRecording = false;
            this.Dispatcher.BeginInvoke(new NoArgDelegate(UpdateState));
        }
Exemple #5
0
        /// <summary>
        /// Records streams from the Kinect sensor to an event file
        /// </summary>
        /// <param name="client">KStudioClient which is connected to the Kinect service</param>
        /// <param name="filePath">Path to new event file which will be created for recording</param>
        /// <param name="duration">How long the recording should last before being stopped</param>
        /// <param name="streamNames">Collection of streams to include in the recording</param>
        public static void RecordClip(KStudioClient client, string filePath, TimeSpan duration, IEnumerable <string> streamNames)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (!client.IsServiceConnected)
            {
                throw new InvalidOperationException(Strings.ErrorNotConnected);
            }

            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            HashSet <Guid> streamDataTypeIds = new HashSet <Guid>();
            KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
            KStudioRecording recording = null;

            // decide which streams to record
            if (streamNames != null && streamNames.Count <string>() > 0)
            {
                streamDataTypeIds = StreamSupport.ConvertStreamsToGuids(streamNames);
                StreamSupport.VerifyStreamsForRecordAndPlayback(streamDataTypeIds);
            }
            else
            {
                if (Path.GetExtension(filePath).ToLower().Equals(Strings.XrfExtension))
                {
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.RawIr);
                }
                else
                {
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.Ir);
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.Depth);
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.Body);
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.BodyIndex);
                }
            }

            // verify streams are recordable by the Kinect sensor
            foreach (Guid stream in streamDataTypeIds)
            {
                KStudioEventStream eventStream = client.GetEventStream(stream, KStudioEventStreamSemanticIds.KinectDefaultSensorProducer);
                if (!eventStream.IsRecordable)
                {
                    throw new InvalidOperationException(string.Format(Strings.ErrorRecordingStreamNotSupported, StreamSupport.ConvertStreamGuidToString(stream)));
                }

                streamCollection.Add(stream);
            }

            // fix file extension, if necessary
            if (streamDataTypeIds.Contains(KStudioEventStreamDataTypeIds.RawIr) && Path.GetExtension(filePath).ToUpperInvariant().Equals(Strings.XefExtension.ToUpperInvariant()))
            {
                Path.ChangeExtension(filePath, Strings.XrfExtension);
            }

            // attempt to record streams for the specified duration
            try
            {
                recording = client.CreateRecording(filePath, streamCollection);
            }
            catch (Exception)
            {
                //K4W supports uncompressed and compressed color, so if we get an error, try recording the other type
                streamCollection = StreamSupport.CreateStreamCollection(streamDataTypeIds, true);
                recording        = client.CreateRecording(filePath, streamCollection);
            }

            using (recording)
            {
                recording.StartTimed(duration);
                while (recording.State == KStudioRecordingState.Recording)
                {
                    Thread.Sleep(500);
                }

                if (recording.State == KStudioRecordingState.Error)
                {
                    throw new InvalidOperationException(Strings.ErrorRecordingFailed);
                }
            }
        }