If you read the above article, you will understand the details.
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
#Demo of Microsoft Computer Vision API
# Python 2 /3 Operated in both systems
#
#
# Usage: python ms_cv_api_exp.py (image_url)
#
#reference
# http://qiita.com/kosfuji/items/621cbedfad0eb68b2f5d
# https://dev.projectoxford.ai/docs/services/56f91f2d778daf23d8ec6739/operations/56f91f2e778daf14a499e1fa
#
from __future__ import print_function
import sys
PY3 = sys.version_info[0] == 3
if PY3:
from urllib.parse import urlencode
from http.client import HTTPSConnection
else:
from urllib import urlencode
from httplib import HTTPSConnection
def main(image_url):
headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '(Put your subscription key here)',
}
params = urlencode({'visualFeatures': 'Description'})
try:
conn = HTTPSConnection('api.projectoxford.ai')
conn.request("POST", "/vision/v1.0/analyze?%s" % params,
"{'url': '%s'}" % image_url,
headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: {} url".format(sys.argv[0]))
main(sys.argv[1])
If you have a Subscription key, you can play a lot of analysis for URLs with the above tools.
This is Monet's "Impression, Sunrise"
Result is……
{
"description": {
"tags": [
"building",
"water",
"street",
"red",
"light",
"sunset",
"painting",
"large",
"city",
"white",
"bus",
"standing",
"rain",
"walking",
"traffic",
"colorful",
"man",
"blurry",
"riding",
"parked",
"people",
"river",
"night"
],
"captions": [
{
"text": "a painting of a river",
"confidence": 0.6266185233006358
}
]
},
"requestId": "f4ead5ca-0c3c-4e41-97ef-df5d8e2e566d",
"metadata": {
"width": 1000,
"height": 776,
"format": "Png"
}
}
I also judged it in a great Impressionist painting.
This is also Monet's "Boulevard des Capucines"
Result is……
{
"description": {
"tags": [
"outdoor",
"tree",
"snow",
"mountain",
"covered",
"group",
"standing",
"large",
"water",
"riding",
"field"
],
"captions": [
{
"text": "a view of a mountain",
"confidence": 0.41440203405943216
}
]
},
"requestId": "a41ea71a-6e1d-416f-b34e-aa19b98c03e0",
"metadata": {
"width": 736,
"height": 1000,
"format": "Jpeg"
}
}
Eh, mountains ...? (´ ・ ω ・ `)
It's a little messy API, but I personally thought it was "awesome" below
"Stop" sign
Result is……
{
"description": {
"tags": [
"building",
"sign",
"outdoor",
"red",
"stop",
"street",
"pole",
"front",
"traffic",
"sitting",
"black",
"city",
"white",
"close",
"side",
"large",
"blue",
"standing",
"train"
],
"captions": [
{
"text": "a red stop sign sitting on the side of a building",
"confidence": 0.8758533311779192
}
]
},
"requestId": "2b687702-9442-45cd-bd5c-7de6be37440d",
"metadata": {
"width": 1000,
"height": 1334,
"format": "Png"
}
}
I'm hitting ~
As I learned from talking to other people, the Japanese "stop" sign is a kind of Galapagos.
Therefore, in order to judge "a red stop sign" with this figure, it is necessary to include such Japanese in the learning data. It seems that it is properly in the training data.
This time it was free because it was a preview. According to the description, "5,000 transactions per month, 20 per minute." It's tough to use it seriously at work, but it's enough to play at this level.
The price story is here. https://www.microsoft.com/cognitive-services/en-us/pricing
Recommended Posts