1+ import com .microsoft .azure .cognitiveservices .vision .computervision .*;
2+ import com .microsoft .azure .cognitiveservices .vision .computervision .models .*;
3+
4+ import java .io .File ;
5+ import java .nio .file .Files ;
6+ import java .util .ArrayList ;
7+ import java .util .List ;
8+
19/**
210 * Computer Vision Quickstart - Java
311 *
412 * Prerequisites:
513 * - Download/clone the project.
6- * - From your Azure account, get your subscription key and the endpoint, which should look similar to:
7- https://westus.api.cognitive.microsoft.com/ (make sure your region matches your subscription), then
8- * set as environment variables with the names COMPUTER_VISION_SUBSCRIPTION_KEY and COMPUTER_VISION_REGION.
14+ * - From your Azure account, get your subscription key and the endpoint, and add them as
15+ environment variables named COMPUTER_VISION_SUBSCRIPTION_KEY and COMPUTER_VISION_ENDPOINT.
916 * - Create a 'src/main/java/resources' folder and add images (landmark.jpg and printed_text.jpg) from here:
1017 * https://github.com/Azure-Samples/cognitive-services-sample-data-files/tree/master/ComputerVision/Images
1118 * - Install the Microsoft Cognitive Services Computer Vision libraries:
3138 * NOTE: Ignore the "Warning..." text in the console when run. The sample still runs fine despite it.
3239 */
3340
34- import com .microsoft .azure .cognitiveservices .vision .computervision .*;
35- import com .microsoft .azure .cognitiveservices .vision .computervision .models .*;
36-
37- import java .io .File ;
38- import java .nio .file .Files ;
39-
40- import java .util .ArrayList ;
41- import java .util .List ;
42-
4341class ComputerVisionQuickstart {
4442 public static void main (String [] args ) {
4543
@@ -56,20 +54,22 @@ public static void main(String[] args) {
5654 * AUTHENTICATE
5755 * Create a client that authorizes your Computer Vision subscription key and region.
5856 */
59- String computerVisionKey = System .getenv ("COMPUTER_VISION_SUBSCRIPTION_KEY" );
60- if (computerVisionKey == null ) {
61- System .out .println ("\n \n Please set the COMPUTER_VISION_SUBSCRIPTION_KEY environment variable.\n **Note that you might need to restart your shell or IDE.**\n " );
57+ String subscriptionKey = System .getenv ("COMPUTER_VISION_SUBSCRIPTION_KEY" );
58+ if (subscriptionKey != "COMPUTER_VISION_SUBSCRIPTION_KEY" ) {
59+ System .out .println ("\n \n Please set the COMPUTER_VISION_SUBSCRIPTION_KEY environment variable." +
60+ "\n **You might need to restart your shell or IDE after setting it.**\n " );
6261 System .exit (0 );
6362 }
6463
65- String computerVisionRegion = System .getenv ("COMPUTER_VISION_ENDPOINT" );
66- if (computerVisionRegion == null ) {
67- System .out .println ("\n \n Please set the COMPUTERVISION_REGION environment variable.\n **Note that you might need to restart your shell or IDE.**\n " );
64+ String endpoint = System .getenv ("COMPUTER_VISION_ENDPOINT" );
65+ if (endpoint != "COMPUTER_VISION_ENDPOINT" ) {
66+ System .out .println ("\n \n Please set the COMPUTER_VISION_ENDPOINT environment variable." +
67+ "\n **You might need to restart your shell or IDE after setting it.**\n " );
6868 System .exit (0 );
6969 }
7070
71- String endpointURL = ( "https://" ). concat ( computerVisionRegion ). concat ( ".api.cognitive.microsoft.com" );
72- ComputerVisionClient computerVisionClient = ComputerVisionManager .authenticate (computerVisionKey ).withEndpoint (endpointURL );
71+ ComputerVisionClient computerVisionClient =
72+ ComputerVisionManager .authenticate (subscriptionKey ).withEndpoint (endpoint );
7373 /**
7474 * END - Authenticate
7575 */
0 commit comments