Esempio n. 1
0
        /// <summary>
        /// Calls the Payoff service method
        /// </summary>
        public static async Task <string> Payoff(ResolverData data)
        {
            var handler = new HttpClientHandler();

            handler.PreAuthenticate = handler.SupportsPreAuthenticate();

            using (var client = new HttpClient(handler))
            {
                try
                {
                    // formulate full url
                    string url = string.Format(_payoffPathV2, data.Host, data.Payload, data.Type);
                    AppendClientData(ref url, data);

                    var now = DateTime.UtcNow;
                    client.DefaultRequestHeaders.Date = now;
                    string body    = SerializeObject(CreateMetricV2()).ToString();
                    int    lenBody = Encoding.UTF8.GetByteCount(body);
                    var    content = new StringContent(body);
                    content.Headers.ContentType = MediaTypeHeaderValue.Parse(_contentType);

                    // set user credentials in Authorization header
                    string authInfo = CreateAuthorizationHeader(url, "POST", lenBody, _contentType, now);
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", authInfo);

                    // make request
                    HttpResponseMessage response;
                    try
                    {
                        Elapsed.Restart();
                        response = await client.PostAsync(url, content);
                    }
                    finally { Elapsed.Stop(); }

                    StatusCode = response.StatusCode;
                    if (!response.IsSuccessStatusCode)
                    {
                        return("StatusCode: " + StatusCode);
                    }

                    var result = response.Content.ReadAsStringAsync().Result;
                    return(JsonIO.FormatFragment(result));
                }
                catch (Exception e)
                {
                    var error = string.Format("Exception: " + e.Message);
                    if (e.InnerException != null)
                    {
                        error += string.Format("\nInner Exception: " + e.InnerException.Message);
                    }

                    return(error);
                }
            }
        }
        public void DetectFaces(Mat inputGrayImage, double scaleFactor, int numberOfNeighbors, Size minSize)
        {
            if (IsEnabled == false)
            {
                return;
            }
            Trace.Assert(inputGrayImage != null);
            Elapsed.Restart();

            DetectedFaceRects = HaarCascade.DetectMultiScale(inputGrayImage, scaleFactor, numberOfNeighbors, HaarDetectionType.ScaleImage, minSize);

            Elapsed.Stop();
            var fps = (1000.0 / (double)Elapsed.ElapsedMilliseconds);

            FpsFiltered = 0.7 * FpsFiltered + 0.3 * fps;
        }
Esempio n. 3
0
        public void DetectFaces(OpenCvSharp.Mat inputColorImage)
        {
            if (IsEnabled == false || DlibDnnMmod == null)
            {
                return;
            }
            Trace.Assert(inputColorImage != null);
            Elapsed.Restart();

            Image.SetBitmap(inputColorImage.ToBitmap());
            DetectedFaceRects = DlibDnnMmod.DetectFaces(Image)
                                .Select(e => new OpenCvSharp.Rect(e.X, e.Y, e.Width, e.Height));

            Elapsed.Stop();
            var fps = (1000.0 / (double)Elapsed.ElapsedMilliseconds);

            FpsFiltered = 0.7 * FpsFiltered + 0.3 * fps;
        }
Esempio n. 4
0
        public void DetectFaceLandmarks(OpenCvSharp.Mat inputColorImage, double threshold)
        {
            if (IsEnabled == false)
            {
                return;
            }
            Trace.Assert(inputColorImage != null);
            Elapsed.Restart();

            Image.SetBitmap(inputColorImage.ToBitmap());
            FaceLandmarkArray = DlibFaceLandmark.DetectFaceLandmarks(Image, threshold);
            DetectedFaceRects = FaceLandmarkArray.Select(e => new OpenCvSharp.Rect(e.Rect.X, e.Rect.Y, e.Rect.Width, e.Rect.Height));

            Elapsed.Stop();
            var fps = (1000.0 / (double)Elapsed.ElapsedMilliseconds);

            FpsFiltered = 0.7 * FpsFiltered + 0.3 * fps;
        }
Esempio n. 5
0
        /// <summary>
        /// Calls the IsAvailable service method
        /// </summary>
        public static async Task <string> IsAvailable(ResolverData data)
        {
            using (var client = new HttpClient())
            {
                try
                {
                    // formulate full url
                    string url = string.Format(_availPathTestDb, data.Host);
                    AppendClientData(ref url, data);

                    // make request
                    HttpResponseMessage response;
                    try
                    {
                        Elapsed.Restart();
                        response = await client.GetAsync(url);
                    }
                    finally { Elapsed.Stop(); }

                    StatusCode = response.StatusCode;
                    if (!response.IsSuccessStatusCode)
                    {
                        return("StatusCode: " + StatusCode);
                    }

                    var result = response.Content.ReadAsStringAsync().Result;
                    return(JsonIO.FormatFragment(result));
                }
                catch (Exception e)
                {
                    var error = string.Format("Exception: " + e.Message);
                    if (e.InnerException != null)
                    {
                        error += string.Format("\nInner Exception: " + e.InnerException.Message);
                    }

                    return(error);
                }
                finally
                {
                    Elapsed.Stop();
                }
            }
        }