When I tried using Microsoft's Computer Vision API, I recognized the Galapagos sign "Stop"

Recent image recognition ability-MS's cutting-edge research results I tried using the Computer Vision API in Python

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"

Impression_Sunrise.png

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"

The_Boulevard_des_Capucines.jpg

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 Tomare.png

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.

The international standard is an octagonal "stop (pause)" road sign. Why did it become an inverted triangle in Japan?

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

When I tried using Microsoft's Computer Vision API, I recognized the Galapagos sign "Stop"
I tried using the Google Cloud Vision API
I tried using the checkio API
I tried using the BigQuery Storage API
I tried using the API of the salmon data project
[Python] I tried collecting data using the API of wikipedia
I tried the Google Cloud Vision API for the first time
[For beginners] I tried using the Tensorflow Object Detection API
I tried the Naro novel API 2
I tried the Naruro novel API
I tried using the COTOHA API (there is code on GitHub)
I tried using Twitter api and Line api
I tried using YOUTUBE Data API V3
I tried using UnityCloudBuild API from Python
I tried to summarize various sentences using the automatic summarization API "summpy"
When introducing the Google Cloud Vision API to rails, I followed the documentation.
I tried to touch the COTOHA API
I tried using scrapy for the first time
I checked the library for using the Gracenote API
I tried using Remote API on GAE / J
I tried hitting the Qiita API from go
vprof --I tried using the profiler for Python
I tried "License OCR" with Google Vision API
I tried using PyCaret at the fastest speed
I tried to touch the API of ebay
I tried using the Datetime module by Python
I tried "Receipt OCR" with Google Vision API
I tried using the image filter of OpenCV
I tried using the functional programming library toolz
A story that was convenient when I tried using the python ip address module
I tried to notify the update of "Become a novelist" using "IFTTT" and "Become a novelist API"
I tried to score the syntax that was too humorous and humorous using the COTOHA API.
I tried to automatically collect erotic images from Twitter using GCP's Cloud Vision API
Initial settings when using the foursquare API in python
[Linux] I tried using the genetic statistics software PLINK
I tried clustering ECG data using the K-Shape method
I tried to approximate the sin function using chainer
I tried APN (remote notification) using Parse.com REST API
[MNIST] I tried Fine Tuning using the ImageNet model.
I tried to identify the language using CNN + Melspectogram
I tried to complement the knowledge graph using OpenKE
I tried hitting the API with echonest's python client
I tried to compress the image using machine learning
[For those who want to use TPU] I tried using the Tensorflow Object Detection API 2
I tried to automate the construction of a hands-on environment using IBM Cloud's SoftLayer API
I tried using parameterized
I tried using argparse
I tried using mimesis
I tried using anytree
I tried using aiomysql
I tried using Summpy
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried using openpyxl
I tried using Ipython
I tried using PyCaret
I tried using cron