Watson 视觉识别 API 更新

Watson visual recognition API update

IBM Cloud Object Storage 的 public 图像似乎无法与 Watson 视觉识别相关联。两种服务之间的调用类型发生了一些变化。 我下面的代码用于工作但知道它说没有 "images founds" 。

import json
from os.path import join, dirname
from os import environ
import sys
import os 
import boto3
import pprint
from boto3 import client
from botocore.utils import fix_s3_host
from watson_developer_cloud import VisualRecognitionV3


param_1= "MY S3 KEY"
param_2= "MY S3 SECRET KEY "
param_3= "https://s3-api.us-geo.objectstorage.softlayer.net"  
param_4= "MY BUCKET "
param_5= "MY WATSON API KEY "

#The Name of my image I want to analyse that is currently in my bucket and is made public
objectNMAE='THIEF.jpg'

s3ressource = client(
    service_name='s3', 
    endpoint_url= param_3,
    aws_access_key_id= param_1,
    aws_secret_access_key=param_2,
    use_ssl=True,
    )
visual_recognition = VisualRecognitionV3('2016-05-20', api_key=param_5)

#The URL of my image I made public with Public ACL
urltobeanalysed="%s/%s/%s" % (param_3,param_4,objectNMAE)   

#For Debug, I use an image that can be viewed in a web-browser
URL2="https://fr.wikipedia.org/wiki/Barack_Obama#/media/File:President_Barack_Obama.jpg"

print(json.dumps(visual_recognition.classify(images_url=urltobeanalysed), indent=2))

更重要的是,public 制作的图像以前显示在我的浏览器中,现在当我输入 URL 时,它正在下载。有什么线索吗?

在对 SO 进行一些研究之后,IBM COS 似乎与 AWS S3 行为保持一致,他们改变了 object header 行为中的一些内容。 我必须将内容类型指定为 image/jpeg: 'contentType' => 'image/jpeg'

否则没有任何显示。不,它有效。

请注意,您在代码中提供的图像是 wiki 页面 的 URL 显示的大图像。您应该在 API 调用中提供的图像的直接 link 是 this one。 (尝试在浏览器中右键单击图片,然后根据您的浏览器执行类似 "Copy image location" 的操作)。