예제 #1
0
        private static InteropFace.TrackedCallback GetTrackCallback(TaskCompletionSource <FaceTrackingResult> tcs)
        {
            return((IntPtr sourceHandle, IntPtr trackingModelHandle, IntPtr engineCfgHandle,
                    IntPtr locationPtr, double confidence, IntPtr _) =>
            {
                try
                {
                    Quadrangle area = null;
                    if (locationPtr != IntPtr.Zero)
                    {
                        area = Marshal.PtrToStructure <global::Interop.MediaVision.Quadrangle>(locationPtr).ToApiStruct();
                    }

                    Log.Info(MediaVisionLog.Tag, $"Tracked area : {area}, confidence : {confidence}");

                    if (!tcs.TrySetResult(new FaceTrackingResult(locationPtr != IntPtr.Zero, confidence, area)))
                    {
                        Log.Error(MediaVisionLog.Tag, "Failed to set tracking result");
                    }
                }
                catch (Exception e)
                {
                    MultimediaLog.Error(MediaVisionLog.Tag, "Setting tracking result failed.", e);
                    tcs.TrySetException(e);
                }
            });
        }
예제 #2
0
        private void RegisterOutputAvailableCallback()
        {
            _outputBufferAvailableCb = (packetHandle, _) =>
            {
                if (_outputAvailable == null)
                {
                    Interop.MediaPacket.Destroy(packetHandle);
                    return;
                }

                OutputAvailableEventArgs args = null;
                try
                {
                    args = new OutputAvailableEventArgs(packetHandle);
                }
                catch (Exception e)
                {
                    Interop.MediaPacket.Destroy(packetHandle);

                    MultimediaLog.Error(typeof(MediaCodec).FullName, "Failed to raise OutputAvailable event", e);
                }

                if (args != null)
                {
                    _outputAvailable?.Invoke(this, args);
                }
            };

            int ret = Interop.MediaCodec.SetOutputBufferAvailableCb(_handle, _outputBufferAvailableCb);

            MultimediaDebug.AssertNoError(ret);
        }
예제 #3
0
        private static InteropImage.TrackedCallback GetCallback(TaskCompletionSource <Quadrangle> tcs)
        {
            return((IntPtr sourceHandle, IntPtr imageTrackingModelHandle, IntPtr engineCfgHandle, IntPtr locationPtr, IntPtr _) =>
            {
                try
                {
                    Quadrangle region = null;
                    if (locationPtr != IntPtr.Zero)
                    {
                        region = Marshal.PtrToStructure <global::Interop.MediaVision.Quadrangle>(locationPtr).ToApiStruct();
                    }

                    Log.Info(MediaVisionLog.Tag, $"Image tracked, region : {region}");

                    if (!tcs.TrySetResult(region))
                    {
                        Log.Info(MediaVisionLog.Tag, "Failed to set track result");
                    }
                }
                catch (Exception e)
                {
                    MultimediaLog.Error(MediaVisionLog.Tag, "Failed to handle track result", e);
                    tcs.TrySetException(e);
                }
            });
        }
예제 #4
0
 internal override void OnEventDetected(IntPtr trigger, IntPtr source, int streamId,
                                        IntPtr result, IntPtr _)
 {
     try
     {
         Detected?.Invoke(this, CreatePersonAppearanceChangedEventArgs(result));
     }
     catch (Exception e)
     {
         MultimediaLog.Error(MediaVisionLog.Tag, "Failed to invoke Recognized event.", e);
     }
 }
예제 #5
0
        private void RegisterOutputAvailableCallback()
        {
            _outputBufferAvailableCb = (packetHandle, _) =>
            {
                if (_outputAvailable == null)
                {
                    try
                    {
                        Native.Destroy(packetHandle).ThrowIfFailed("Failed to destroy packet.");
                    }
                    catch (Exception)
                    {
                        // Do not throw exception in pinvoke callback.
                    }

                    return;
                }

                OutputAvailableEventArgs args = null;
                try
                {
                    args = new OutputAvailableEventArgs(packetHandle);
                }
                catch (Exception e)
                {
                    try
                    {
                        Native.Destroy(packetHandle).ThrowIfFailed("Failed to destroy packet.");
                    }
                    catch
                    {
                        // Do not throw exception in pinvoke callback.
                    }

                    MultimediaLog.Error(typeof(MediaCodec).FullName, "Failed to raise OutputAvailable event", e);
                }

                if (args != null)
                {
                    _outputAvailable?.Invoke(this, args);
                }
            };

            Native.SetOutputBufferAvailableCb(_handle, _outputBufferAvailableCb).
            ThrowIfFailed("Failed to set output buffer available callback.");
        }
예제 #6
0
        private static InteropBarcode.DetectedCallback GetCallback(TaskCompletionSource <IEnumerable <Barcode> > tcs)
        {
            return((IntPtr mvSource, IntPtr engineCfg, Unmanaged.Quadrangle[] locations, string[] messages,
                    BarcodeType[] types, int numberOfBarcodes, IntPtr userData) =>
            {
                Log.Info(MediaVisionLog.Tag, $"Barcodes detected, count : {numberOfBarcodes}");

                try
                {
                    tcs.TrySetResult(CreateBarcodes(locations, messages, types, numberOfBarcodes));
                }
                catch (Exception e)
                {
                    MultimediaLog.Error(MediaVisionLog.Tag, "Failed to handle barcode detection callback", e);
                    tcs.TrySetException(e);
                }
            });
        }
예제 #7
0
 private static InteropImage.RecognizedCallback GetCallback(
     TaskCompletionSource <IEnumerable <ImageRecognitionResult> > tcs)
 {
     return((IntPtr source, IntPtr engineConfig, IntPtr imageObjectHandles,
             IntPtr[] locations, uint numOfObjects, IntPtr _) =>
     {
         try
         {
             if (!tcs.TrySetResult(CreateResults(locations, numOfObjects)))
             {
                 Log.Info(MediaVisionLog.Tag, "Failed to set recognition result");
             }
         }
         catch (Exception e)
         {
             MultimediaLog.Error(MediaVisionLog.Tag, "Failed to handle recognition result", e);
             tcs.TrySetException(e);
         }
     });
 }
예제 #8
0
 private static InteropFace.RecognizedCallback GetRecognizedCallback(
     TaskCompletionSource <FaceRecognitionResult> tcs)
 {
     return((IntPtr sourceHandle, IntPtr recognitionModelHandle,
             IntPtr engineCfgHandle, IntPtr faceLocationPtr, IntPtr faceLabelPtr, double confidence, IntPtr _) =>
     {
         try
         {
             if (!tcs.TrySetResult(CreateRecognitionResult(faceLocationPtr, faceLabelPtr, confidence)))
             {
                 Log.Error(MediaVisionLog.Tag, "Failed to set result");
             }
         }
         catch (Exception e)
         {
             MultimediaLog.Error(MediaVisionLog.Tag, "Setting recognition result failed.", e);
             tcs.TrySetException(e);
         }
     });
 }