示例#1
0
        /// <summary>
        /// Creates asynchronously the Media Capture which will process the depth stream images
        /// </summary>
        /// <param name="clbk">The Callback object to call when the hand detection status changes.</param>
        /// <returns>The asynchronous task</returns>
        public async Task InitializeAsync(IHDMediaSinkClbk clbk)
        {
            //Create the media capture
            Debug.WriteLine("Creating a media capture...");
            m_mediaCapture = new MediaCapture();
            await m_mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings()
            {
                VideoDeviceId        = m_mediaInfo.DeviceInformation.Id,
                SharingMode          = MediaCaptureSharingMode.SharedReadOnly,
                MemoryPreference     = MediaCaptureMemoryPreference.Auto,      //For the Hololens, MediaCaptureMemoryPreference.CPU does not work
                StreamingCaptureMode = StreamingCaptureMode.Video
            });

            //Find a correct video profile with the best capabilities (resolution)
            Debug.WriteLine("Search a video profile...");
            VideoEncodingProperties videoProfile = null;
            var mediaProperties = m_mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);

            UInt32 maxHeight = 0;

            foreach (var mediaProp in mediaProperties)
            {
                VideoEncodingProperties videoProp = mediaProp as VideoEncodingProperties;
                Debug.WriteLine($"VideoProp : {videoProp.Type}:{videoProp.Subtype} {videoProp.Width}x{videoProp.Height}");
                if (videoProp.Subtype == "ARGB32" || videoProp.Subtype == "L8" || videoProp.Subtype == "D16" || videoProp.Subtype == "D8" || videoProp.Subtype == "L16" || videoProp.Subtype == "RGB24")
                {
                    if (maxHeight < videoProp.Height)
                    {
                        videoProfile = videoProp;
                        maxHeight    = videoProp.Height;
                    }
                }
            }

            if (videoProfile == null)
            {
                Debug.WriteLine("No video profile found...");
                await Task.FromResult <Windows.Foundation.IAsyncAction>(null);
            }

            else
            {
                Debug.WriteLine($"Starting to preview {m_mediaInfo.DeviceInformation.Name} : {m_mediaInfo.DeviceInformation.Id} at {videoProfile.Width}x{videoProfile.Height}: {videoProfile.Subtype}");

                //Create the video encoding
                MediaEncodingProfile profile = new MediaEncodingProfile();
                profile.Video = videoProfile;
                profile.Audio = null;

                //Create and start preview in the MediaSink
                Debug.WriteLine(m_mediaInfo.DeviceInformation.Name);
                m_mediaSink = new HDMediaSinkProxy();
                IMediaExtension ext = await m_mediaSink.InitializeAsync(clbk, profile.Video);

                await m_mediaCapture.StartPreviewToCustomSinkAsync(profile, ext);
            }

            Debug.WriteLine("End of Create media capture async");
        }
示例#2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="group"></param>
 /// <param name="info"></param>
 private HandDetector(MediaFrameSourceGroup group, MediaFrameSourceInfo info)
 {
     m_mediaGroup = group;
     m_mediaInfo  = info;
     m_mediaSink  = null;
 }