Using curl to send requests

This example uses curl to send a request to the Vision API. It sends the image below by specifying its publicly-accessible HTTPS URL:

https://cloud.google.com/vision/images/rushmore.jpg

Install curl

curl is a command-line tool for making client-side URL requests. It's available for most platforms, including Linux, Windows, and macOS.

Download curl and install or unpack it onto your system.

Creating the request JSON

We'd like to request landmark detection and web entity detection on this image. The request JSON looks like:

{
  "requests": [
    {
      "image": {
        "source": {
          "imageUri": "https://cloud.google.com/vision/images/rushmore.jpg"
        }
      },
      "features": [
        {
          "type": "LANDMARK_DETECTION",
          "maxResults": 1
        },
        {
          "type": "WEB_DETECTION",
          "maxResults": 2
        }
      ]
    }
  ]
}

Save the code above as a file called request.json in your working directory.

Sending the request

curl is used to send the request to Cloud Vision. Enter the following on your command line:

curl -v -s -H "Content-Type: application/json" \
    https://vision.googleapis.com/v1/images:annotate?key=API_KEY \
    --data-binary @request.json

You'll need to specify your own API key. If you don't know yours, follow the instructions in the Authenticate chapter of the Vision API documentation.

Response

The Cloud Vision API returns the response. Since the JSON specified maxResults to return for each annotation type, the response includes 1 landmarkAnnotations result and 2 webEntities results.

{
  "responses": [
    {
      "landmarkAnnotations": [
        {
          "mid": "/m/019dvv",
          "description": "Mount Rushmore",
          "score": 0.8757957,
          "boundingPoly": {
            "vertices": [
              {
                "x": 321,
                "y": 195
              },
              {
                "x": 777,
                "y": 195
              },
              {
                "x": 777,
                "y": 510
              },
              {
                "x": 321,
                "y": 510
              }
            ]
          },
          "locations": [
            {
              "latLng": {
                "latitude": 43.878264,
                "longitude": -103.45700740814209
              }
            }
          ]
        }
      ],
      "webDetection": {
        "webEntities": [
          {
            "entityId": "/m/019dvv",
            "score": 255.8336,
            "description": "Mount Rushmore National Memorial"
          },
          {
            "entityId": "/m/0373w4",
            "score": 12.14976,
            "description": "Crazy Horse Memorial"
          }
        ],
        "fullMatchingImages": [
          {
            "url": "https://tinahanagan.files.wordpress.com/2012/04/dsc_0597.jpg"
          }
        ],
        "partialMatchingImages": [
          {
            "url": "https://i1.wp.com/eightsails.files.wordpress.com/2016/10/img_2138.jpg"
          },
          {
            "url": "https://i1.wp.com/littlezenmonkey.com/wp-content/uploads/2016/05/IMG_6994.jpg"
          }
        ],
        "visuallySimilarImages": [
          {
            "url": "http://media.gettyimages.com/photos/the-famous-landmark-mount-rushmore-on-a-perfect-weather-day-picture-id106682515?s=170667a"
          },
          {
            "url": "http://www.clevelandseniors.com/images/funny/mount-rushmore.jpg"
          }
        ]
      }
    }
  ]
}

Send feedback about...

Google Cloud Vision API Documentation