Пример #1
0
        private static MediaVisionSource GenerateSource(BarcodeGenerationConfiguration config,
                                                        string message, BarcodeType type, int qrMode, int qrEcc, int qrVersion)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            ValidationUtil.ValidateEnum(typeof(BarcodeType), type);

            MediaVisionSource source = new MediaVisionSource();

            try
            {
                InteropBarcode.GenerateSource(EngineConfiguration.GetHandle(config),
                                              message, type, qrMode, qrEcc, qrVersion, source.Handle).
                Validate("Failed to generate source");
            }
            catch (Exception)
            {
                source.Dispose();
                throw;
            }
            return(source);
        }
Пример #2
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);
                }
        }
Пример #3
0
        /// <summary>
        /// Determines facial expression on media source.
        /// </summary>
        /// <param name="source">The source of the media to recognize facial expression for.</param>
        /// <param name="bound">The location bounding the face at the source.</param>
        /// <param name="config">The configuration used for expression 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.</exception>
        /// <exception cref="ObjectDisposedException">
        ///     <paramref name="source"/> has already been disposed of.<br/>
        ///     -or-<br/>
        ///     <paramref name="config"/> has already been disposed of.
        /// </exception>
        /// <exception cref="NotSupportedException">The feature is not supported.</exception>
        /// <feature>http://tizen.org/feature/vision.face_recognition</feature>
        /// <since_tizen> 4 </since_tizen>
        public static async Task <FacialExpression> RecognizeFacialExpressionAsync(MediaVisionSource source,
                                                                                   Rectangle bound, FaceRecognitionConfiguration config)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            TaskCompletionSource <FacialExpression> tcsResult = new TaskCompletionSource <FacialExpression>();

            InteropFace.MvFaceFacialExpressionRecognizedCallback cb = (IntPtr sourceHandle, IntPtr engineCfgHandle,
                                                                       global::Interop.MediaVision.Rectangle faceLocation, FacialExpression facialExpression, IntPtr _) =>
            {
                Log.Info(MediaVisionLog.Tag, $"Facial expression recognized, expression : {facialExpression}");
                if (!tcsResult.TrySetResult(facialExpression))
                {
                    Log.Error(MediaVisionLog.Tag, "Failed to set facial result");
                }
            };

            using (var cbKeeper = ObjectKeeper.Get(cb))
            {
                InteropFace.RecognizeFacialExpression(source.Handle, EngineConfiguration.GetHandle(config),
                                                      bound.ToMarshalable(), cb).
                Validate("Failed to perform facial expression recognition.");

                return(await tcsResult.Task);
            }
        }
Пример #4
0
 internal void InvokeAddSource(SurveillanceSource source, SurveillanceEngineConfiguration config)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     SubscribeEventTrigger(Handle, source.StreamId, EngineConfiguration.GetHandle(config),
                           OnEventDetected).Validate("Failed to subscribe trigger");
 }
Пример #5
0
        private void InvokeFill(MediaVisionSource source, ImageFillConfiguration config, Rectangle?area)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            InvokeFill(source.Handle, EngineConfiguration.GetHandle(config), area).
            Validate("Failed to fill the image object");
        }
Пример #6
0
        /// <summary>
        /// Detects barcodes on the source and reads the message from it with <see cref="BarcodeDetectionConfiguration"/>.
        /// </summary>
        /// <param name="source">The <see cref="MediaVisionSource"/> instance.</param>
        /// <param name="roi">Region of interest - rectangular area on the source which will be used for
        ///     barcode detection. Note that roi should be inside area on the source.</param>
        /// <param name="config">The configuration of the barcode detector. This value can be null.</param>
        /// <returns>A task that represents the asynchronous detect operation.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
        /// <exception cref="NotSupportedException">The feature is not supported.</exception>
        /// <exception cref="ObjectDisposedException">
        ///     <paramref name="source"/> already has been disposed of.<br/>
        ///     -or-<br/>
        ///     <paramref name="config"/> already has been disposed of.
        /// </exception>
        /// <seealso cref="Barcode"/>
        /// <since_tizen> 4</since_tizen>
        public static async Task <IEnumerable <Barcode> > DetectAsync(MediaVisionSource source,
                                                                      Rectangle roi, BarcodeDetectionConfiguration config)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

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

            using (var cb = ObjectKeeper.Get(GetCallback(tcs)))
            {
                InteropBarcode.Detect(source.Handle, EngineConfiguration.GetHandle(config),
                                      roi.ToMarshalable(), cb.Target).Validate("Failed to detect barcode.");

                return(await tcs.Task);
            }
        }
Пример #7
0
        /// <summary>
        /// Detects faces on the source.<br/>
        /// Each time when DetectAsync is called, a set of the detected faces at the media source are received asynchronously.
        /// </summary>
        /// <param name="source">The source of the media where faces will be detected.</param>
        /// <param name="config">The configuration of engine will be used for detecting. This value can be null.</param>
        /// <returns>A task that represents the asynchronous detect operation.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
        /// <exception cref="NotSupportedException">The feature is not supported.</exception>
        /// <feature>http://tizen.org/feature/vision.face_recognition</feature>
        /// <since_tizen> 4 </since_tizen>
        public static async Task <Rectangle[]> DetectAsync(MediaVisionSource source,
                                                           FaceDetectionConfiguration config)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            TaskCompletionSource <Rectangle[]> tcs = new TaskCompletionSource <Rectangle[]>();

            using (var cb = ObjectKeeper.Get(GetCallback(tcs)))
            {
                InteropFace.Detect(source.Handle, EngineConfiguration.GetHandle(config), cb.Target).
                Validate("Failed to perform face detection");

                return(await tcs.Task);
            }
        }
Пример #8
0
        private static void GenerateImage(BarcodeGenerationConfiguration config,
                                          string message, BarcodeType type, BarcodeImageConfiguration imageConfig,
                                          int qrMode, int qrEcc, int qrVersion)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (imageConfig == null)
            {
                throw new ArgumentNullException(nameof(imageConfig));
            }

            ValidationUtil.ValidateEnum(typeof(BarcodeType), type);

            InteropBarcode.GenerateImage(EngineConfiguration.GetHandle(config), message,
                                         imageConfig.Width, imageConfig.Height, type, qrMode, qrEcc, qrVersion,
                                         imageConfig.Path, imageConfig.Format).
            Validate("Failed to generate image");
        }
Пример #9
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);
            }
        }
Пример #10
0
        private static async Task <FaceRecognitionResult> InvokeRecognizeAsync(MediaVisionSource source,
                                                                               FaceRecognitionModel recognitionModel, Rectangle?area,
                                                                               FaceRecognitionConfiguration config)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (recognitionModel == null)
            {
                throw new ArgumentNullException(nameof(recognitionModel));
            }

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

            using (var cb = ObjectKeeper.Get(GetRecognizedCallback(tcs)))
            {
                InvokeRecognize(source.Handle, recognitionModel.Handle, EngineConfiguration.GetHandle(config),
                                cb.Target, area).Validate("Failed to perform face recognition.");

                return(await tcs.Task);
            }
        }
Пример #11
0
 /// <summary>
 /// Learns the face recognition model with <see cref="FaceRecognitionConfiguration"/>.
 /// </summary>
 /// <remarks>
 /// Before you start the learning process, face recognition models have to be filled with the training data - face image examples.
 /// These examples have to be provided by <see cref="Add(MediaVisionSource, int)"/> or <see cref="Add(MediaVisionSource, int, Rectangle)"/>.
 /// Recognition accuracy is usually increased when the different examples of the identical faces are added more and more.
 /// But it depends on the used learning algorithm.
 /// </remarks>
 /// <param name="config">The configuration used for learning of the recognition models. This value can be null.</param>
 /// <exception cref="ObjectDisposedException">
 ///     The <see cref="FaceRecognitionModel"/> has already been disposed of.<br/>
 ///     -or-<br/>
 ///     <paramref name="config"/> has already been disposed of.
 /// </exception>
 /// <exception cref="InvalidOperationException">No examples added.</exception>
 /// <seealso cref="Add(MediaVisionSource, int)"/>
 /// <seealso cref="Add(MediaVisionSource, int, Rectangle)"/>
 /// <since_tizen> 4 </since_tizen>
 public void Learn(FaceRecognitionConfiguration config)
 {
     InteropModel.Learn(EngineConfiguration.GetHandle(config), Handle).
     Validate("Failed to learn");
 }