2013-10-27 27 views
1

我想上傳一個圖像的實例到faceplusplus api。如果我從驅動器或URL上傳圖像,但是當我使用圖像的實例時出現錯誤,則一切正常。以下是我的代碼如下。Python Faceplusplus API

import image 
import requests 
import StringIO 
from facepp import API, File 


url = "http://blogs.reuters.com/great-debate/files/2013/07/obama-best.jpg" 
response = requests.get(url) 
img = Image.open(StringIO(response.content)) 

result = api.detection.detect(img = File(img), mode = 'normal') 

由於使用Google App Engine,我必須從url創建一個圖像實例。我應該使用什麼方法將圖像上傳到Faceplusplus API?

這裏是我的錯誤: 類型錯誤:強迫爲Unicode:需要字符串或緩衝區,如發現

你的幫助是非常讚賞。

謝謝!

回答

0

步驟1:

更新facepp.py

class File(object): 
"""an object representing a local file""" 
path = None 
content = None 
# add a parameter content 
def __init__(self, path,content=None): 
    self.path = path 
    if content : 
     self.content = content 
    else : 
     self._get_content() 

第二步:

url = "http://blogs.reuters.com/great-debate/files/2013/07/obama-best.jpg" 
response = requests.get(url) 
result = api.detection.detect(img=File('{custom image name}',response.content), mode = 'normal') 

打印結果