Example #1
0
        /// <summary>
        /// Recognizes the given image objects on the source image.<br/>
        /// </summary>
        /// <param name="source">The source image on which image objects will be recognized.</param>
        /// <param name="imageObjects">The array of image objects which will be processed as targets of recognition.</param>
        /// <param name="config">The configuration used for recognition. This value can be null.</param>
        /// <returns>A task that represents the asynchronous recognition operation.</returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="source"/> is null.<br/>
        ///     -or-<br/>
        ///     <paramref name="imageObjects"/> is null.<br/>
        ///     -or-<br/>
        ///     <paramref name="imageObjects"/> contains null elements.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="imageObjects"/> has no elements.(The length is zero.)</exception>
        /// <exception cref="NotSupportedException">The feature is not supported.</exception>
        /// <exception cref="ObjectDisposedException">
        ///     <paramref name="source"/> has already been disposed of.<br/>
        ///     -or-<br/>
        ///     <paramref name="config"/> has already been disposed of.
        /// </exception>
        /// <feature>http://tizen.org/feature/vision.image_recognition</feature>
        /// <since_tizen> 4 </since_tizen>
        public static async Task <IEnumerable <ImageRecognitionResult> > RecognizeAsync(MediaVisionSource source,
                                                                                        ImageObject[] imageObjects, ImageRecognitionConfiguration config)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (imageObjects == null)
            {
                throw new ArgumentNullException(nameof(imageObjects));
            }
            if (imageObjects.Length == 0)
            {
                throw new ArgumentException("No image object to recognize.", nameof(imageObjects));
            }

            var tcs = new TaskCompletionSource <IEnumerable <ImageRecognitionResult> >();

            using (var cb = ObjectKeeper.Get(GetCallback(tcs)))
                using (var imageHandles = ObjectKeeper.Get(GetHandles(imageObjects)))
                {
                    InteropImage.Recognize(source.Handle, imageHandles.Target, imageHandles.Target.Length,
                                           EngineConfiguration.GetHandle(config), cb.Target).
                    Validate("Failed to perform image recognition.");

                    return(await tcs.Task);
                }
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageObject"/> class from the specified file.
 /// </summary>
 /// <remarks>
 /// ImageObject has been saved by <see cref="Save(string)"/> can be loaded.
 /// </remarks>
 /// <param name="path">Path to the image object to load.</param>
 /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
 /// <exception cref="FileNotFoundException"><paramref name="path"/> is invalid.</exception>
 /// <exception cref="NotSupportedException">
 ///     The feature is not supported.<br/>
 ///     -or-<br/>
 ///     <paramref name="path"/> is not supported file.
 /// </exception>
 /// <exception cref="UnauthorizedAccessException">No permission to access the specified file.</exception>
 /// <seealso cref="Save(string)"/>
 /// <since_tizen> 4 </since_tizen>
 public ImageObject(string path)
 {
     if (path == null)
     {
         throw new ArgumentNullException(nameof(path));
     }
     InteropImage.Load(path, out _handle).Validate("Failed to load image object from file");
 }
Example #3
0
        /// <summary>
        /// Releases the resources used by the <see cref="ImageObject"/> object.
        /// </summary>
        /// <param name="disposing">
        /// true to release both managed and unmanaged resources; otherwise false to release only unmanaged resources.
        /// </param>
        /// <since_tizen> 4 </since_tizen>
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            InteropImage.Destroy(_handle);
            _disposed = true;
        }
Example #4
0
        private MediaVisionError InvokeFill(IntPtr source, IntPtr config, Rectangle?area)
        {
            if (area == null)
            {
                return(InteropImage.Fill(Handle, config, source, IntPtr.Zero));
            }

            var rect = area.Value.ToMarshalable();

            return(InteropImage.Fill(Handle, config, source, ref rect));
        }
Example #5
0
        /// <summary>
        /// Gets the label for the image object.
        /// </summary>
        /// <returns>
        /// The label value if the <see cref="ImageObject"/> has label, otherwise null.
        /// </returns>
        /// <exception cref="ObjectDisposedException">The <see cref="ImageObject"/> has already been disposed of.</exception>
        /// <seealso cref="SetLabel(int)"/>
        /// <since_tizen> 4 </since_tizen>
        public int?GetLabel()
        {
            var ret = InteropImage.GetLabel(Handle, out var label);

            if (ret == MediaVisionError.NoData)
            {
                return(null);
            }

            ret.Validate("Failed to get label");
            return(label);
        }
Example #6
0
        /// <summary>
        /// Saves the image object.
        /// </summary>
        /// <param name="path">Path to the file to save the model.</param>
        /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
        /// <exception cref="UnauthorizedAccessException">No permission to write to the specified path.</exception>
        /// <exception cref="ObjectDisposedException">The <see cref="ImageObject"/> has already been disposed of.</exception>
        /// <exception cref="DirectoryNotFoundException">The directory for <paramref name="path"/> does not exist.</exception>
        /// <since_tizen> 4 </since_tizen>
        public void Save(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            var ret = InteropImage.Save(path, Handle);

            if (ret == MediaVisionError.InvalidPath)
            {
                throw new DirectoryNotFoundException($"The directory for the path({path}) does not exist.");
            }

            ret.Validate("Failed to save the image object");
        }
Example #7
0
        /// <summary>
        /// Tracks the given image tracking model on the current frame and <see cref="ImageTrackingConfiguration"/>.
        /// </summary>
        /// <param name="source">The current image of sequence where the image tracking model will be tracked.</param>
        /// <param name="trackingModel">The image tracking model which processed as target of tracking.</param>
        /// <param name="config">The configuration used for tracking. This value can be null.</param>
        /// <returns>A task that represents the asynchronous tracking operation.</returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="source"/> is null.<br/>
        ///     -or-<br/>
        ///     <paramref name="trackingModel"/> is null.
        /// </exception>
        /// <exception cref="NotSupportedException">The feature is not supported.</exception>
        /// <exception cref="ObjectDisposedException">
        ///     <paramref name="source"/> has already been disposed of.<br/>
        ///     -or-<br/>
        ///     <paramref name="trackingModel"/> has already been disposed of.<br/>
        ///     -or-<br/>
        ///     <paramref name="config"/> has already been disposed of.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="trackingModel"/> has no target.</exception>
        /// <seealso cref="ImageTrackingModel.SetTarget(ImageObject)"/>
        /// <feature>http://tizen.org/feature/vision.image_recognition</feature>
        /// <since_tizen> 4 </since_tizen>
        public static async Task <Quadrangle> TrackAsync(MediaVisionSource source,
                                                         ImageTrackingModel trackingModel, ImageTrackingConfiguration config)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (trackingModel == null)
            {
                throw new ArgumentNullException(nameof(trackingModel));
            }

            TaskCompletionSource <Quadrangle> tcs = new TaskCompletionSource <Quadrangle>();

            using (var cb = ObjectKeeper.Get(GetCallback(tcs)))
            {
                InteropImage.Track(source.Handle, trackingModel.Handle, EngineConfiguration.GetHandle(config),
                                   cb.Target).Validate("Failed to perform image tracking.");

                return(await tcs.Task);
            }
        }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageObject"/> class.
 /// </summary>
 /// <exception cref="NotSupportedException">The feature is not supported.</exception>
 /// <since_tizen> 4 </since_tizen>
 public ImageObject()
 {
     InteropImage.Create(out _handle).Validate("Failed to create image object");
 }
Example #9
0
 /// <summary>
 /// Sets the label for the <see cref="ImageObject"/>.
 /// </summary>
 /// <param name="label">The label which will be assigned to the image object.</param>
 /// <seealso cref="GetLabel"/>
 /// <since_tizen> 4 </since_tizen>
 public void SetLabel(int label)
 {
     InteropImage.SetLabel(Handle, label).Validate("Failed to set label");
 }