问题遇到的现象和发生背景
第一行设置图片路径,如果图片是存放在阿里云OSS服务器上的图片, 如何打开文件
问题相关代码
original_file = 'C:\\Users\\ZJY\\Desktop\\test.jpg'
_image = Image.open(original_file)
draw = ImageDraw.Draw(_image)
language = "cn|en"
location = "true"
# headers=getHeader(language, location) 图像识别
r = requests.post(URL, headers=getHeader(), data=getBody(original_file))
result_json= json.loads(r.content)
data = result_json["data"]["block"]
text_font = ImageFont.truetype('c:/windows/fonts/Verdana.ttf', 100)
for words_result in data[0]['line']:
print(words_result['location'],words_result['word'])
location = words_result['location']
rect =(location['top_left']['x'],location['top_left']['y'],location['right_bottom']['x'],location['right_bottom']['y'])
draw.rectangle(rect,None,'red')
draw.text((location['right_bottom']['x']+10,location['top_left']['y']+5),expression_parser(words_result['word'][0]['content']),(255,0,0),font=text_font)
_image.save('result.jpg','jpeg')
_image
尝试了很多方法好像都不行,