该服务使用深度学习算法来识别场景、物体和人脸。一样,你也能够根据本身的需求来建立并训练你本身的分类器算法
在bluemix上建立该服务实例,而且得到api-key,具体参见详见Watson使用指南。json
图片分类(Classify an image)segmentfault
使用默认分类器,上传图片或图片地址便可进行识别。图片必须是jpg或png格式。对于待识别图片而言,得到的响应包括一些列选定分类器的得分,这些分数从0到1,越高的得分说明越接近该分类器,返回的得分信息是0.5以上的。为了得到最好的识别效果,推荐上传224x224px及以上大小的图片。api
参数:数组
api_key (query型,必须,你的API密钥)app
version (query型,必须,版本信息,当前最新2016-05-20 )ide
images_file (multipart/form-data,必须,图片或压缩包。压缩包最大5MB,最多20张图片)学习
parameters (multipart/form-data,JSON格式数据)ui
url (string型,图片地址)url
classifier_ids (数组,待使用分类器)
owners (数组,分类器拥有者,IBM或你本身)
threshold (float型,返回的最小得分)
Accept-Language (Header型,输出语言)
import json from os.path import join, dirname from os import environ from watson_developer_cloud import VisualRecognitionV3 visual_recognition = VisualRecognitionV3('2016-05-20', api_key='{api-key}') print(json.dumps(visual_recognition.classify(images_url=https://www.ibm.com/ibm/ginni/images/ginni_bio_780x981_v4_03162016.jpg), indent=2))
返回结果
参数:
images(结果数组)
classifiers(分类器数组)
classes (分类器中的标签数组)
class (分类器标签)
score (得分)
classifier_id (分类器惟一标识)
name (分类器名称)
image (图片文件所在路径)
source_url (图片来源地址)
resolved_url (图片解析地址)
images_processed(处理图片数量)
error (错误反馈)
error_id (错误标识ID)
description (错误描述)
warnings (警告提示数组)
{ "images": [ { "classifiers": [ { "classes": [ { "class": "apple", "score": 0.645656 }, { "class": "fruit", "score": 0.598688 }, { "class": "food", "score": 0.598688 }, { "class": "orange", "score": 0.5 }, { "class": "vegetable", "score": 0.28905 }, { "class": "tree", "score": 0.28905 } ], "classifier_id": "default", "name": "default" }, { "classes": [ { "class": "orange", "score": 0.635488 } ], "classifier_id": "fruits_1050835757", "name": "fruits" }, ], "image": "orange-apple-banana-isolated.jpg" }, { "classifiers": [ { "classes": [ { "class": "fruit", "score": 0.916827 }, { "class": "vegetation", "score": 0.768525 }, { "class": "market", "score": 0.768525 }, { "class": "food", "score": 0.377541 }, { "class": "mercado", "score": 0.28905 }, { "class": "vegetable", "score": 0.268941 } ], "classifier_id": "default", "name": "default" }, { "classes": [ { "class": "apple", "score": 0.541237 } ], "classifier_id": "fruits_1050835757", "name": "fruits" }, ], "resolved_url": "https://c1.staticflickr.com/9/8803/17306765722_a2d0 be2f9e_b.jpg", "source_url": "https://flic.kr/p/snkGus" } ] "images_processed": 2 }
人脸识别(Detect faces)
分析图片中的人脸信息,好比近似年龄、性别、若是是名人还有姓名。支持jpg或png格式。该功能是不能训练的,而且不能用于生物学脸部识别。
参数:
api_key (query型,必须,你的API密钥)
version (query型,必须,版本信息,当前最新2016-05-20 )
images_file (multipart/form-data,必须,图片或压缩包。压缩包最大5MB,最多20张图片)
parameters (multipart/form-data,JSON格式数据,图片地址)
import json from os.path import join, dirname from os import environ from watson_developer_cloud import VisualRecognitionV3 visual_recognition = VisualRecognitionV3('2016-05-20', api_key='{api_key}') print(json.dumps(visual_recognition.detect_faces(images_url=https://www.ibm.com/ibm/ginni/images/ginni_bio_780x981_v4_03162016.jpg), indent=2))
返回结果
参数:
images (结果数组)
faces (脸部信息数组)
age (年龄信息)
max (可能最大年龄)
min (可能最小年龄)
face_location (识别区域)
height (识别区域高度)
left(识别区域左上角x坐标)
top (识别区域左上角y坐标)
width (识别区域宽度)
gender (性别信息)
identity (若是是名人,返回信相关息,不然返回空)
name (识别人物的姓名)
type_hierarchy (关于名人,找到其属于的层次类型)
score (得分)
image (图片路径)
source_url (来源地址)
resolved_url (图片解析地址)
images_processed(处理图片数量)
error (错误反馈)
error_id (错误标识ID)
description (错误描述)
warnings (警告提示数组)
{ "images": [ { "faces": [ { "age": { "max": 54, "min": 45, "score": 0.372036 }, "face_location": { "height": 75, "left": 256, "top": 93, "width": 67 }, "gender": { "gender": "MALE", "score": 0.99593 }, "identity": { "name": "Barack Obama", "score": 0.989013, "type_hierarchy": "/people/politicians/democrats/barack obama" } } ], "image": "prez.jpg" } ], "images_processed": 1 } }