1- Copyright ( c ) Microsoft Corporation . All rights reserved .
2- Licensed under the MIT License.
1+ // Copyright (c) Microsoft Corporation.All rights reserved.
2+ // Licensed under the MIT License.
33
44using System ;
55using System . IO ;
66using System . Net . Http ;
77using System . Net . Http . Headers ;
88using System . Text ;
99
10- namespace CSHttpClientSample
10+ /* This sample uses the Azure Face API to detect faces in an image and then
11+ * returns a lot of facial features, in addition to gender and age.
12+ * Face API:
13+ * https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236
14+ */
15+
16+ namespace FaceSample
1117{
1218 static class Program
1319 {
14- // **********************************************
15- // *** Update or verify the following values. ***
16- // **********************************************
17-
1820 // Add your Azure Face subscription key and endpoint to your environment variables
19- const string subscriptionKey = Environment . GetEnvironmentVariable ( "FACE_SUBSCRIPTION_KEY" ) ;
20- const string uriBase = Environment . GetEnvironmentVariable ( "FACE_ENDPOINT" ) ;
21-
21+ private static string subscriptionKey = Environment . GetEnvironmentVariable ( "FACE_SUBSCRIPTION_KEY" ) ;
22+ private static string uriBase = Environment . GetEnvironmentVariable ( "FACE_ENDPOINT" ) ;
2223
2324 static void Main ( )
2425 {
25- // Get the path and filename to process from the user.
26- Console . WriteLine ( "Detect faces:" ) ;
27- Console . Write ( "Enter the path to an image with faces that you wish to analzye: " ) ;
28- string imageFilePath = Console . ReadLine ( ) ;
26+ // Download an image from here:
27+ // https://github.com/Azure-Samples/cognitive-services-sample-data-files/tree/master/ComputerVision/Images
28+ // Or add your own image and put into your bin\Debug\netcoreapp3.0\Images folder.
29+ string imageFilePath = @"Images\faces.jpg" ;
2930
3031 // Execute the REST API call.
3132 MakeAnalysisRequest ( imageFilePath ) ;
@@ -34,7 +35,6 @@ static void Main()
3435 Console . ReadLine ( ) ;
3536 }
3637
37-
3838 /// <summary>
3939 /// Gets the analysis of the specified image file by using the Computer Vision REST API.
4040 /// </summary>
@@ -47,10 +47,11 @@ static async void MakeAnalysisRequest(string imageFilePath)
4747 client . DefaultRequestHeaders . Add ( "Ocp-Apim-Subscription-Key" , subscriptionKey ) ;
4848
4949 // Request parameters. A third optional parameter is "details".
50- string requestParameters = "returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise" ;
50+ string requestParameters =
51+ "returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise" ;
5152
5253 // Assemble the URI for the REST API Call.
53- string uri = uriBase + "?" + requestParameters ;
54+ string uri = uriBase + "/face/v1.0/detect ?" + requestParameters ;
5455
5556 HttpResponseMessage response ;
5657
@@ -75,7 +76,6 @@ static async void MakeAnalysisRequest(string imageFilePath)
7576 }
7677 }
7778
78-
7979 /// <summary>
8080 /// Returns the contents of the specified file as a byte array.
8181 /// </summary>
@@ -88,7 +88,6 @@ static byte[] GetImageAsByteArray(string imageFilePath)
8888 return binaryReader . ReadBytes ( ( int ) fileStream . Length ) ;
8989 }
9090
91-
9291 /// <summary>
9392 /// Formats the given JSON string by adding line breaks and indents.
9493 /// </summary>
0 commit comments