我目前正在开发简单的演示,如何使用 Azure 自定义视觉和 Azure OCR 组合来捕获对象上的一些文本,例如车牌、公交车号码等。
将图像发送到 Azure OCR 时遇到问题,如下所示: “字节”对象没有属性“读取”
只需从相机捕获帧并使用 Python SDK 将其发送到 Azure OCR Read。
有人有类似上面的问题吗? 如何修复它?以及将帧发送到 Azure OCR 读取的最佳方式
下面是我的代码中的一些片段(假设框架已经从自定义视觉边界过程中裁剪):
highest_prob = predictions[0]
image_text = detect_text(frame, highest_prob)
功能:
def detect_text(image, highest_prob):
# Convert image to byte string
img_str = cv2.imencode(".jpg", image)[1].tostring()
#Call API with image and raw response (allows you to get the operation location)
recognize_printed_results = computervision_client.read_in_stream(img_str, raw=True)
使用相机捕获:
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
最佳答案
计算机视觉库无法从根环境访问,我们需要在虚拟环境中访问这些库。针对CV2,升级计算机视觉版本,解决问题。读取操作需要以计算机视觉库支持的形式进行一些升级。
pip install --upgrade azure-cognitiveservices-vision-computervision
使用ComputerVisionClient.analyze_image()
读取图像列表。不是作为一个单独的实体。
关于Python SDK Azure 计算机视觉 : 'bytes' object has no attribute 'read' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74474621/