Пример #1
0
        public CameraSource(ref RosConnector rosConnector, CameraHandler handler, string name, double publishPeriod) : base()
        {
            string topic = "/hololens/" + name;

            publisher      = new RosSharp.RosBridgeClient.NonMono.Publisher <RosSharp.RosBridgeClient.Messages.Sensor.Image>(ref rosConnector, topic);
            CameraHandler_ = handler;
            CameraHandler_.FrameReadyToPublish += PublishFrame;
            Debug.WriteLine("Publishing a new topic: " + topic);

            StartReader();
        }
Пример #2
0
        public async Task GetDataSources()
        {
            // If pose is supported and selected add pose source
            //var ver = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily;
            //if (ver == "Windows.Holographic")
            //{
            //    bool isSelected;
            //    Config.SourceSelectionDictionary.TryGetValue(Config.Pose, out isSelected);
            //    if (isSelected)
            //    {
            //        DataSources.Add(new PoseSource(ref RosConnector, ref SharedTimer)
            //        {
            //            SourceName = Config.Pose,
            //            PublishPeriod = 1 / Config.HololensPoseFPS
            //        });
            //    }
            //}

            // Check for any available cameras
            var possibleSourceKinds = new MediaFrameSourceKind[] { MediaFrameSourceKind.Depth, MediaFrameSourceKind.Infrared, MediaFrameSourceKind.Color };
            var groups = await MediaFrameSourceGroup.FindAllAsync();

            // Find the group that exposes all of the sensors for streaming
            foreach (var g in groups)
            {
                if (g.DisplayName == "Sensor Streaming")
                {
                    Debug.WriteLine("Found Sensor Streaming Source Group");
                    var mediaCapture = new MediaCapture();
                    await mediaCapture.InitializeAsync(
                        new MediaCaptureInitializationSettings()
                    {
                        SourceGroup          = g,
                        MemoryPreference     = MediaCaptureMemoryPreference.Cpu,
                        StreamingCaptureMode = StreamingCaptureMode.Video
                    }
                        );

                    var sources = mediaCapture.FrameSources.Where(fs => possibleSourceKinds.Contains(fs.Value.Info.SourceKind)).Select(fs => fs.Value);

                    foreach (var source in sources)
                    {
                        string originalSourceName = source.Info.Id.Substring(source.Info.Id.IndexOf("Source#"), 8);
                        string assignedSourceName;
                        Config.DataSourceDictionary.TryGetValue(originalSourceName, out assignedSourceName);

                        bool isSelected;
                        Config.SourceSelectionDictionary.TryGetValue(assignedSourceName, out isSelected);
                        if (isSelected)
                        {
                            double assignedFrameRate;
                            Config.FrameRateDictionary.TryGetValue(assignedSourceName, out assignedFrameRate);
                            double assignedPublishPeriod = 1.0 / (double)assignedFrameRate;
                            int    originalFPS           = (int)source.Info.VideoProfileMediaDescription[0].FrameRate;

                            CameraHandler handler = new CameraHandler(source.Info, mediaCapture, assignedPublishPeriod);
                            await handler.SetupReaderAsync();

                            DataSources.Add(new CameraSource(ref RosConnector, handler, assignedSourceName, assignedPublishPeriod)
                            {
                                Resolution  = $"{ source.Info.VideoProfileMediaDescription[0].Width } x { source.Info.VideoProfileMediaDescription[0].Height }",
                                OriginalFPS = originalFPS,
                                SourceName  = assignedSourceName
                            });
                        }
                    }
                    break;
                }
            }
        }