Python SDK Azure 计算机视觉 : 'bytes' object has no attribute 'read'

标签 python azure camera real-time azure-cognitive-services

我目前正在开发简单的演示,如何使用 Azure 自定义视觉和 Azure OCR 组合来捕获对象上的一些文本,例如车牌、公交车号码等。

将图像发送到 Azure OCR 时遇到问题,如下所示: “字节”对象没有属性“读取”enter image description here

只需从相机捕获帧并使用 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/

相关文章:

python - 在python中解析日志文件

python - 如何在 python 中表示二叉树?

c# - 通过 Windows 窗体 c# 将文件上传到 Blob

azure - 中继 WebHttp 中继绑定(bind)到 Web api 服务

camera - 我可以将 Sony HDR-AS100 连接到现有接入点吗

python - 类内的装饰器,带有接受参数的函数的参数

python - 通过 matplotlib 绘制 3 ODE 系统的相图

azure - Azure Devops 中的工作项、看板和冲刺之间有什么区别

java - Libgdx第一人称视角控制

iOS 应用程序不返回到同一个 View Controller