LoginSignup
2
2

More than 5 years have passed since last update.

Python で、Watoson の画像認識を使う

Last updated at Posted at 2017-08-11

Wastosn の VisualRecogintion を使って、画像に写っているものが何かを認識するサンプルです。

参考ページ
IBM Watson Visual Recognition V3 Python Tutorial

実行したときの様子

watson_aug1101.png

get_visual.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
#   get_visual.py
#
#                   Aug/11/2017
#
import sys
import json
import requests
from watson_developer_cloud import VisualRecognitionV3
# --------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
api_key="31b9172e4832c2339dc9e6d2e89cfadc5110692"
#
visual_recognition = VisualRecognitionV3('2016-05-20', api_key=api_key)

jpg_in=sys.argv[1]
#
image_file=open(jpg_in,'rb')
results = visual_recognition.classify(images_file=image_file)
image_file.close()
#
for it in range(3):
    cc0=results["images"][0]["classifiers"][0]["classes"][it]
    print(cc0["class"],cc0["score"])
#
sys.stderr.write("*** 終了 ***\n")
# --------------------------------------------------------------------
2
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2