简体   繁体   中英

Python SDK Azure Computer Vision: 'bytes' object has no attribute 'read'

I am currently developing simple demo how to capture some text over the object such as license plate, Bus number, etc using combination Azure custom vision and Azure OCR.

I have issue when sending image to Azure OCR like below: 'bytes' object has no attribute 'read' 在此处输入图像描述

Simply by capturing frame from camera and send it to Azure OCR Read using Python SDK.

Anyone has similar issue like above? How to fix it? and the best way to send frame into Azure OCR Read

below some snippet from my code (Let say the frame already cropped from custom vision boundaries process):

highest_prob = predictions[0]
image_text = detect_text(frame, highest_prob)

to function:

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)

Capturing camera using:

cap = cv2.VideoCapture(0)
while True:
    ret, frame = cap.read()
    if not ret:
        break

Computer vision libraries cannot be accessible from the root environment and we need to get the libraries to access inside the virtual environment. With respect to CV2, upgrade the version of computer vision which solves the issue. The read operation needs to have some upgrade in the form of computer vision library support.

pip install --upgrade azure-cognitiveservices-vision-computervision

use ComputerVisionClient.analyze_image() to read the list of images. Not as an individual entity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM