• Martin Thoma
  • Home
  • Categories
  • Tags
  • Archives
  • Support me

Microsoft Vision API

Contents

  • See also

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

  • Cognitive Services: You have to apply there. 5,000 transactions per month, 20 per minute is for free.
  • The 86-category concept
  • Computer Vision API - v1.0

Published

Mär 31, 2016
by Martin Thoma

Category

Cyberculture

Tags

  • Machine Learning 81
  • Microsoft 6

Contact

  • Martin Thoma - A blog about Code, the Web and Cyberculture
  • E-mail subscription
  • RSS-Feed
  • Privacy/Datenschutzerklärung
  • Impressum
  • Powered by Pelican. Theme: Elegant by Talha Mansoor