Esempio n. 1
0
        static async Task Main(string[] args)
        {
            var           imagePath   = @"oscars-2017.jpg";
            var           urlAddress  = "http://localhost:6001/api/faces";
            ImageUtility  imgUtil     = new ImageUtility();
            var           bytes       = imgUtil.ConvertToBytes(imagePath);
            List <byte[]> faceList    = null;
            var           byteContent = new ByteArrayContent(bytes);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.PostAsync(urlAddress, byteContent))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    faceList = JsonConvert.DeserializeObject <List <byte[]> >(apiResponse);
                }
            }
            if (faceList != null && faceList.Count > 0)
            {
                for (int i = 0; i < faceList.Count; i++)
                {
                    imgUtil.FromBytesToImage(faceList[i], "face" + i);
                }
            }
        }
Esempio n. 2
0
        static async Task Main(string[] args)
        {
            var          imagePath                = @"office.png";
            var          urlAddress               = "http://localhost:6001/api/faces/{0}";
            var          uriWithParm              = new Uri(string.Format(urlAddress, Guid.NewGuid()));
            ImageUtility imageUtility             = new ImageUtility();
            var          bytes                    = imageUtility.ConvertToBytes(imagePath);
            Tuple <List <byte[]>, Guid> faceTuple = null;
            var byteContent = new ByteArrayContent(bytes);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.PostAsync(uriWithParm, byteContent))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    faceTuple = JsonConvert.DeserializeObject <Tuple <List <byte[]>, Guid> >(apiResponse);
                }
            }
            if (faceTuple.Item1.Count > 0)
            {
                for (int i = 0; i < faceTuple.Item1.Count; i++)
                {
                    imageUtility.FromBytesToImage(faceTuple.Item1[i], "face" + i);
                }
            }
        }
Esempio n. 3
0
        static async Task Main(string[] args)
        {
            var imagepath  = @"oscar.jpg";
            var urlAddress = @"http://localhost:6000/api/faces";

            ImageUtility imageUtility = new ImageUtility();
            var          bytes        = imageUtility.ConvertToBytes(imagepath);

            List <byte[]> faceList    = null;
            var           byteContent = new ByteArrayContent(bytes);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

            HttpClientHandler clientHandler = new HttpClientHandler();

            clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };

            using var httpClient = new HttpClient(clientHandler);
            using var response   = await httpClient.PostAsync(urlAddress, byteContent);

            string apiResponse = await response.Content.ReadAsStringAsync();

            faceList = JsonConvert.DeserializeObject <List <byte[]> >(apiResponse);

            if (faceList.Count == 0)
            {
                throw new Exception("Face Not Found");
            }

            for (int i = 0; i < faceList.Count; i++)
            {
                imageUtility.FromBytesToImage(faceList[0], $"face{i}.jpg");
            }

            Console.WriteLine($"{faceList.Count} Face(s) Detected.");
        }