/// <summary> /// Detects objects and gets its locations on the source image using inference engine set in <paramref name="config"/>.<br/> /// Each time when DetectAsync is called, a set of the detected objects at the media source are received asynchronously. /// </summary> /// <feature>http://tizen.org/feature/vision.inference</feature> /// <feature>http://tizen.org/feature/vision.inference.image</feature> /// <param name="source">The source of the media where faces will be detected.</param> /// <param name="config">The engine's configuration that will be used for detecting.</param> /// <returns> /// A task that represents the asynchronous detect operation.<br/> /// If there's no detected object, empty collection will be returned. /// </returns> /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="config"/> is null.</exception> /// <exception cref="InvalidOperationException">Internal error.</exception> /// <exception cref="NotSupportedException">The feature is not supported.</exception> /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception> /// <seealso cref="InferenceModelConfiguration"/> /// <since_tizen> 6 </since_tizen> public static async Task <IEnumerable <ObjectDetectionResult> > DetectAsync(MediaVisionSource source, InferenceModelConfiguration config) { // `vision.inference` feature is already checked, when config is created. ValidationUtil.ValidateFeatureSupported(VisionFeatures.InferenceImage); if (source == null) { throw new ArgumentNullException(nameof(source)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } var tcs = new TaskCompletionSource <IEnumerable <ObjectDetectionResult> >(); using (var cb = ObjectKeeper.Get(GetCallback(tcs))) { InteropInference.DetectObject(source.Handle, config.GetHandle(), cb.Target). Validate("Failed to detect object."); return(await tcs.Task); } }
/// <summary> /// Classifies image objects on the source image using inference engine set in <paramref name="config"/>.<br/> /// Each time when DetectAsync is called, a set of the detected faces at the media source are received asynchronously. /// </summary> /// <feature>http://tizen.org/feature/vision.inference</feature> /// <feature>http://tizen.org/feature/vision.inference.image</feature> /// <param name="source">The source of the media where faces will be detected.</param> /// <param name="config">The engine's configuration that will be used for classifying.</param> /// <returns> /// A task that represents the asynchronous classify operation.<br/> /// If there's no classified image object, empty collection will be returned. /// </returns> /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="config"/> is null.</exception> /// <exception cref="InvalidOperationException">Internal error.</exception> /// <exception cref="NotSupportedException">The feature is not supported.</exception> /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception> /// <seealso cref="InferenceModelConfiguration"/> /// <since_tizen> 6 </since_tizen> public static async Task <IEnumerable <ImageClassificationResult> > ClassifyAsync(MediaVisionSource source, InferenceModelConfiguration config) { // `vision.inference` feature is already checked, when config is created. ValidationUtil.ValidateFeatureSupported(VisionFeatures.InferenceImage); if (source == null) { throw new ArgumentNullException(nameof(source)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } var tcs = new TaskCompletionSource <IEnumerable <ImageClassificationResult> >(); using (var cb = ObjectKeeper.Get(GetCallback(tcs))) { IntPtr roiUnmanaged = IntPtr.Zero; try { if (config.Roi.HasValue) { var roi = config.Roi.Value.ToMarshalable(); roiUnmanaged = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(global::Interop.MediaVision.Rectangle))); Marshal.WriteIntPtr(roiUnmanaged, IntPtr.Zero); Marshal.StructureToPtr(roi, roiUnmanaged, false); } InteropInference.ClassifyImage(source.Handle, config.GetHandle(), roiUnmanaged, cb.Target). Validate("Failed to classify image."); } finally { if (roiUnmanaged != IntPtr.Zero) { Marshal.FreeHGlobal(roiUnmanaged); } } return(await tcs.Task); } }
/// <summary> /// Detects Pose landmarks on the source image using inference engine set in <paramref name="config"/>.<br/> /// </summary> /// <remarks> /// To set region-of-interest area in source image, please set <see cref="InferenceModelConfiguration.Roi"/>. /// If not set, full image area will be used to detect Pose landmark. /// </remarks> /// <feature>http://tizen.org/feature/vision.inference</feature> /// <feature>http://tizen.org/feature/vision.inference.face</feature> /// <param name="source">The source of the media where poses will be detected.</param> /// <param name="config">The engine's configuration that will be used for detecting.</param> /// <returns> /// A task that represents the asynchronous detect operation.<br/> /// </returns> /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="config"/> is null.</exception> /// <exception cref="InvalidOperationException">Internal error.</exception> /// <exception cref="NotSupportedException">The feature is not supported.</exception> /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception> /// <seealso cref="InferenceModelConfiguration"/> /// <since_tizen> 9 </since_tizen> public static async Task <Landmark[, ]> DetectAsync(MediaVisionSource source, InferenceModelConfiguration config) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } var tcs = new TaskCompletionSource <Landmark[, ]>(); using (var cb = ObjectKeeper.Get(GetCallback(tcs))) { IntPtr roiUnmanaged = IntPtr.Zero; try { if (config.Roi.HasValue) { var roi = config.Roi.Value.ToMarshalable(); roiUnmanaged = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Unmanaged.Rectangle))); Marshal.WriteIntPtr(roiUnmanaged, IntPtr.Zero); Marshal.StructureToPtr(roi, roiUnmanaged, false); } InteropInference.DetectPoseLandmark(source.Handle, config.GetHandle(), roiUnmanaged, cb.Target). Validate("Failed to detect Pose landmark."); } finally { if (roiUnmanaged != IntPtr.Zero) { Marshal.FreeHGlobal(roiUnmanaged); } } return(await tcs.Task); } }