Esempio n. 1
0
        /// <summary>
        /// Creates SDP answer asynchronously with option to an offer received from a remote peer.
        /// </summary>
        /// <remarks>The WebRTC must be in the <see cref="WebRTCState.Negotiating"/></remarks>
        /// <returns>The SDP answer.</returns>
        /// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception>
        /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
        /// <seealso cref="CreateOfferAsync()"/>
        /// <since_tizen> 9 </since_tizen>
        public async Task <string> CreateAnswerAsync()
        {
            ValidateWebRTCState(WebRTCState.Negotiating);

            var tcsSdpCreated = new TaskCompletionSource <string>();

            NativeWebRTC.SdpCreatedCallback cb = (handle, sdp, _) =>
            {
                tcsSdpCreated.TrySetResult(sdp);
            };

            string answer = null;

            using (var cbKeeper = ObjectKeeper.Get(cb))
            {
                NativeWebRTC.CreateSDPAnswerAsync(Handle, new SafeBundleHandle(), cb, IntPtr.Zero).
                ThrowIfFailed("Failed to create answer asynchronously");

                answer = await tcsSdpCreated.Task.ConfigureAwait(false);

                await Task.Yield();
            }

            return(answer);
        }
Esempio n. 2
0
        /// <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);
            }
        }
Esempio n. 3
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);
                }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
    private void Awake()
    {
        DontDestroyOnLoad(gameObject);

        if (_instance == null)
        {
            _instance = this;
        }
        else if (this != _instance)
        {
            Destroy(this.gameObject);
        }
    }
Esempio n. 6
0
        /// <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);
            }
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
0
        internal async Task <MediaPacket> RunAsync(TransformHandle handle, MediaPacket source)
        {
            Debug.Assert(source.Format is VideoMediaFormat);
            ValidateFormat(source.Format as VideoMediaFormat);

            var tcs = new TaskCompletionSource <MediaPacket>();

            using (var cbKeeper = ObjectKeeper.Get(GetCallback(tcs, source)))
            {
                var result = NativeTransform.Run(handle, source.GetHandle(), cbKeeper.Target);

                if (result == ImageUtilError.NotSupportedFormat)
                {
                    throw new NotSupportedException(
                              GenerateNotSupportedErrorMessage(source.Format as VideoMediaFormat));
                }
                result.ThrowIfFailed("Failed to transform given packet with " + GetType());

                return(await tcs.Task);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Performs face tracking on the source with the trackingModel.
        /// </summary>
        /// <param name="source">The source of the media to recognize face for.</param>
        /// <param name="trackingModel">The model will be used for tracking.</param>
        /// <param name="doLearn">The value indicating whether model learning while tracking. If it is true, then the model will try to learn
        /// (if it supports learning feature), otherwise the model will be not learned during the invoking tracking iteration.
        /// Learning process improves tracking correctness, but can decrease tracking performance.</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="ObjectDisposedException">
        ///     <paramref name="source"/> has already been disposed of.<br/>
        ///     -or-<br/>
        ///     <paramref name="trackingModel"/> has already been disposed of.
        /// </exception>
        /// <exception cref="NotSupportedException">The feature is not supported.</exception>
        /// <exception cref="InvalidOperationException"><paramref name="trackingModel"/> is not prepared.</exception>
        /// <feature>http://tizen.org/feature/vision.face_recognition</feature>
        /// <since_tizen> 4 </since_tizen>
        public static async Task <FaceTrackingResult> TrackAsync(MediaVisionSource source,
                                                                 FaceTrackingModel trackingModel, bool doLearn)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (trackingModel == null)
            {
                throw new ArgumentNullException(nameof(trackingModel));
            }

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

            using (var cb = ObjectKeeper.Get(GetTrackCallback(tcs)))
            {
                InteropFace.Track(source.Handle, trackingModel.Handle, IntPtr.Zero,
                                  cb.Target, doLearn).Validate("Failed to perform face tracking.");

                return(await tcs.Task);
            }
        }
Esempio n. 11
0
        /// <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);
            }
        }
Esempio n. 12
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);
            }
        }
Esempio n. 13
0
        public DataTable GetResult(string tableName)
        {
            if (tableName.Trim().Length == 0)
            {
                return(null);
            }

            ObjectKeeper objKeeper = new ObjectKeeper();

            objKeeper.AddObject(0, _SASWorkSpace.Name, _SASWorkSpace);

            string sql = "select * from " + tableName;

            DataTable        oDT       = new DataTable();
            OleDbDataAdapter obAdapter = new OleDbDataAdapter(sql, _OleDbConnString);

            obAdapter.Fill(oDT);

            objKeeper.RemoveObject(_SASWorkSpace);

            return(oDT);
        }
Esempio n. 14
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);
            }
        }
Esempio n. 15
0
        private static async Task <ThumbnailExtractionResult> ExtractAsyncCore(string path, Size?size,
                                                                               CancellationToken cancellationToken)
        {
            using (var handle = CreateHandle())
            {
                Native.SetPath(handle, path).ThrowIfError("Failed to extract; failed to set the path.");

                if (size.HasValue)
                {
                    Native.SetSize(handle, size.Value.Width, size.Value.Height).
                    ThrowIfError("Failed to extract; failed to set the size");
                }

                var tcs = new TaskCompletionSource <ThumbnailExtractionResult>();

                IntPtr id = IntPtr.Zero;

                try
                {
                    var cb = GetCallback(tcs);
                    using (var cbKeeper = ObjectKeeper.Get(cb))
                    {
                        Native.Extract(handle, cb, IntPtr.Zero, out id)
                        .ThrowIfError("Failed to extract.");

                        using (RegisterCancellationToken(tcs, cancellationToken, handle, Marshal.PtrToStringAnsi(id)))
                        {
                            return(await tcs.Task);
                        }
                    }
                }
                finally
                {
                    LibcSupport.Free(id);
                }
            }
        }