Skip to content

Commit 9867aba

Browse files
authored
Updated libraries
1 parent a1b2b4d commit 9867aba

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

java/Vision/Face1.0.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
//Copyright (c) Microsoft Corporation. All rights reserved.
2-
//Licensed under the MIT License.
3-
4-
// This sample uses the Apache HTTP client library(org.apache.httpcomponents:httpclient:4.2.4)
5-
// and the org.json library (org.json:json:20170516). YOu can download this from Maven repo to the lib directory of your project.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
63

74
import java.net.URI;
85
import org.apache.http.HttpEntity;
@@ -16,33 +13,35 @@
1613
import org.json.JSONArray;
1714
import org.json.JSONObject;
1815

16+
/**
17+
* Include these library jars (or newer +), add to a lib folder:
18+
* commons-logging-4.0.6+
19+
* httpclient-4.5.3+
20+
* httpcore-4.4.13+
21+
* json-20190722+
22+
*
23+
* To compile and run from command line:
24+
* javac Main.java -cp .;lib\*
25+
* java -cp .;lib\* Main
26+
*/
27+
1928
public class Main
2029
{
21-
// **********************************************
22-
// *** Update or verify the following values. ***
23-
// **********************************************
24-
25-
// Replace the subscriptionKey string value with your valid subscription key.
26-
public static final String subscriptionKey = "Enter key here";
30+
// Add your Face subscription key and endpoint to your environment variables.
31+
private static String subscriptionKey = System.getenv("FACE_SUBSCRIPTION_KEY");
32+
private static String baseUrl = System.getenv("FACE_ENDPOINT");
2733

28-
// Replace or verify the region.
29-
//
30-
// You must use the same region in your REST API call as you used to obtain your subscription keys.
31-
// For example, if you obtained your subscription keys from the westus region, replace
32-
// "westcentralus" in the URI below with "westus".
33-
//
34-
// NOTE: Free trial subscription keys are generated in the westcentralus region, so if you are using
35-
// a free trial subscription key, you should not need to change this region.
36-
public static final String uriBase = "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect";
34+
public static final String endpoint= baseUrl + "/face/v1.0/detect";
3735

36+
private static String image = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/Face/images/test-image-person-group.jpg";
3837

3938
public static void main(String[] args)
4039
{
4140
HttpClient httpclient = new DefaultHttpClient();
4241

4342
try
4443
{
45-
URIBuilder builder = new URIBuilder(uriBase);
44+
URIBuilder builder = new URIBuilder(endpoint);
4645

4746
// Request parameters. All of them are optional.
4847
builder.setParameter("returnFaceId", "true");
@@ -58,7 +57,7 @@ public static void main(String[] args)
5857
request.setHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
5958

6059
// Request body.
61-
StringEntity reqEntity = new StringEntity("{\"url\":\"https://upload.wikimedia.org/wikipedia/commons/c/c3/RH_Louise_Lillian_Gish.jpg\"}");
60+
StringEntity reqEntity = new StringEntity("{\"url\":\"" + image + "\"}");
6261
request.setEntity(reqEntity);
6362

6463
// Execute the REST API call and get the response entity.

0 commit comments

Comments
 (0)