Microsoft Vision API

· by

Microsoft just released a Computer Vision API. I tried it with a couple of Unidentified objects of Wikipedia and was not really impressed.

Here is how to use it:

#!/usr/bin/env python

"""Example how to use the Microsoft Vision API."""

import httplib
import urllib
import json

headers = {"Content-type": "application/json"}

params = urllib.urlencode(
    {
        # Specify your subscription key
        "subscription-key": "yourhexadecimalone11111111111111",
        # Specify values for optional parameters, as needed
        "visualFeatures": "All",
    }
)

try:
    image_url = "http://www.martin-thoma.de/bilder/Martin_Thoma_web_thumb.jpg"

    conn = httplib.HTTPSConnection("api.projectoxford.ai")
    conn.request(
        "POST", "/vision/v1/analyses?%s" % params, "{'Url': '%s'}" % image_url, headers
    )
    response = conn.getresponse()
    data = response.read()
    data = json.loads(data)
    print(json.dumps(data, sort_keys=True, indent=2))
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

which gives

{
  "adult": {
    "adultScore": 0.01073759701102972,
    "isAdultContent": false,
    "isRacyContent": false,
    "racyScore": 0.015348214656114578
  },
  "categories": [
    {
      "name": "people_",
      "score": 0.8359375
    }
  ],
  "color": {
    "accentColor": "4C5F37",
    "dominantColorBackground": "Green",
    "dominantColorForeground": "Green",
    "dominantColors": [
      "Green"
    ],
    "isBWImg": false
  },
  "faces": [
    {
      "age": 28,
      "faceRectangle": {
        "height": 49,
        "left": 53,
        "top": 42,
        "width": 49
      },
      "gender": "Male"
    }
  ],
  "imageType": {
    "clipArtType": 0,
    "lineDrawingType": 0
  },
  "metadata": {
    "format": "Jpeg",
    "height": 200,
    "width": 134
  },
  "requestId": "7f0af611-1750-4fa2-aa47-a03db286f6a7"
}

See also