我正在使用Ms Azure凭据计算机视觉访问图像文件并从中提取文本,最后将其保存在。txt文件中。代码工作良好的url具有。jpg扩展名。我的代码在
中出现了一些错误- 扩展名为。jpg的图像文件保存在本地文件夹中。
- 图片文件从web与url做。没有。jpg扩展名。
我的代码在这里-in-under
'''url of the remote (web) Image File'''
#remote_image_url = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/ComputerVision/Images/landmark.jpg"
#imagefile = "<filepath>//IMAGE1.JPG"
remote_image_url = "http://site.meishij.net/r/58/25/3568808/a3568808_142682562777944.jpg"
## Saving a url image to local folder as jpg
import requests
pic_url = "http://site.meishij.net/r/58/25/3568808/a3568808_142682562777944.jpg"
#pic_url = "https://wallup.net/new-york-city-manhattan-nyc-usa-new-york-manhattan-usa-city-type-height-panorama-night-pink-sunset-blue-sky-clouds-lights-light-house-building-skyscraper-skyscrapers-5/"
with open('C://Users//ubana//OneDrive//ANIL JOSHI//PROJECTS//CONVERSION TO TXT FILE//IMAGES//pic1.jpg', 'wb') as handle:
response = requests.get(pic_url, stream=True)
if not response.ok:
print (response)
for block in response.iter_content(1024):
if not block:
break
handle.write(block)
'''
Describe an Image - remote
This example describes the contents of an image with the confidence score.
'''
print("===== Describe an image - remote =====")
# Call API
description_results = computervision_client.describe_image(remote_image_url)
# Get the captions (descriptions) from the response, with confidence level
print("Description of remote image: ")
if (len(description_results.captions) == 0):
print("No description detected.")
else:
for caption in description_results.captions:
print("'{}' with confidence {:.2f}%".format(caption.text, caption.confidence * 100))
错误如下
** computervisionerroreexception Traceback(最近一次调用)在5打印("=====描述图像-远程=====")6 #调用API——比;7 description_results = computervision_client. descripbe_image (imgfile)89 #从回复中获取标题(描述),并带有置信度~Anaconda3lib website -packagesazure cognitivesservices visioncomputervisionoperations_computer_vision_client_operations.py in describe_image(self, url, max_candidate, language, description_exclude, custom_headers, raw,operation_config)201202如果响应。Status_code不在[200]:——比;203抛出models. computervisionerroreexception (self。_deserialize、响应)204205 deserialized =无
如果有人能帮我解决这个问题,我将不胜感激
Salil雷
with open('C://Users//ubana//OneDrive//ANIL JOSHI//PROJECTS//CONVERSION TO TXT FILE//IMAGES//pic1.jpg', 'wb') as handle:
是不正确的。也许可以尝试在文件路径中使用双反斜杠而不是正斜杠,如下所示:
with open('C:\Users\ubana\OneDrive\ANIL JOSHI\PROJECTS\CONVERSION TO TXT FILE\IMAGES\pic1.jpg', 'wb') as handle: