async void Setup() { ObjectDetectorDescriptor descriptor = new ObjectDetectorDescriptor(); var m_availableExecutionDevices = await descriptor.GetSupportedExecutionDevicesAsync(); skill = await descriptor.CreateSkillAsync() as ObjectDetectorSkill; // If you don't specify an ISkillExecutionDevice, a default will be automatically selected binding = await skill.CreateSkillBindingAsync() as ObjectDetectorBinding; }
/// <summary> /// Initialize the ObjectDetector skill /// </summary> /// <param name="device"></param> /// <returns></returns> private async Task InitializeObjectDetectorAsync(ISkillExecutionDevice device = null) { if (device != null) { m_skill = await m_descriptor.CreateSkillAsync(device) as ObjectDetectorSkill; } else { m_skill = await m_descriptor.CreateSkillAsync() as ObjectDetectorSkill; } m_binding = await m_skill.CreateSkillBindingAsync() as ObjectDetectorBinding; }
/// <summary> /// Initialize the ObjectDetector skill /// </summary> /// <param name="device"></param> /// <returns></returns> private async Task InitializeObjectDetectorAsync(ISkillExecutionDevice device = null) { if (device != null) { m_skill = await m_descriptor.CreateSkillAsync(device) as ObjectDetectorSkill; } else { m_skill = await m_descriptor.CreateSkillAsync() as ObjectDetectorSkill; } m_binding = await m_skill.CreateSkillBindingAsync() as ObjectDetectorBinding; m_inputImageFeatureDescriptor = m_binding["InputImage"].Descriptor as SkillFeatureImageDescriptor; }
/// <summary> /// Configure an IFrameSource from a StorageFile or MediaCapture instance to produce optionally a specified format of frame /// </summary> /// <param name="source"></param> /// <param name="inputImageDescriptor"></param> /// <returns></returns> private async Task ConfigureFrameSourceAsync(object source, ISkillFeatureImageDescriptor inputImageDescriptor = null) { await m_lock.WaitAsync(); { // Reset bitmap rendering component UIProcessedPreview.Source = null; m_renderTargetFrame = null; m_processedBitmapSource = new SoftwareBitmapSource(); UIProcessedPreview.Source = m_processedBitmapSource; // Clean up previous frame source if (m_frameSource != null) { m_frameSource.FrameArrived -= FrameSource_FrameAvailable; var disposableFrameSource = m_frameSource as IDisposable; if (disposableFrameSource != null) { // Lock disposal based on frame source consumers disposableFrameSource.Dispose(); } } // Create new frame source and register a callback if the source fails along the way m_frameSource = await FrameSourceFactory.CreateFrameSourceAsync( source, (sender, message) => { NotifyUser(message); }, inputImageDescriptor); // TODO: Workaround for a bug in ObjectDetectorBinding when binding consecutively VideoFrames with Direct3DSurface and SoftwareBitmap m_binding = await m_skill.CreateSkillBindingAsync() as ObjectDetectorBinding; } m_lock.Release(); // If we obtained a valid frame source, start it if (m_frameSource != null) { m_frameSource.FrameArrived += FrameSource_FrameAvailable; await m_frameSource.StartAsync(); } }