我是 Microsoft Azure AI 计算机视觉新手。我在 Python 程序中使用认知服务和计算机视觉客户端来做两件事:
经过大量配置问题(以及 PIP 安装!),我取得了一些成果
从图像中提取文本的代码是:
#Create A ComputerVision Client
client = ComputerVisionClient(ENDPOINT, CognitiveServicesCredentials(API_KEY))
image_path = '/Users/Owner/Documents/Bills Stuff/eBay/Images/Document_20240914_0008.jpg'
#Use Azure AI Cognitive Services to Get the Title and Description of Image
#For the TITLE, Use Optical Character Recognition (OCR) to Read the Text (Caption) on the Image
with open(image_path, "rb") as image_stream:
ocr_results=client.recognize_printed_text_in_stream(image_stream)
if ocr_results.regions:
for region in ocr_results.regions:
for line in region.lines:
print(f" Title: {' '.join([word.text for word in line.words])}")
我的第二点 - 描述效果很好,但是上面的代码根本没有从图像中准确地提取文本。
它很接近,但实际的文字是:“宾夕法尼亚铁路马蹄曲线风景”
我上面提供的代码返回:“中国铁路马蹄曲线内”
有没有办法改进我的代码,使这个结果更加准确?
添加:如果我减小/增加图像的大小,代码会拾取更多或更少的单词 - 也许我需要以某种方式给代码更多的时间来处理图像??
谢谢!