TypeError: get() expected a dict or protobuf message, got <class 'numpy.ndarray'>

TypeError: get() expected a dict or protobuf message, got <class 'numpy.ndarray'>

我正在尝试使用 OpenCV 拍摄图片的一个区域,然后提取该文本。知道如何修复此错误吗?

roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
cv2.imshow('image2', roi)
cv2.waitKey(0)

response = client.text_detection(image=roi)
texts = response.text_annotations
string = texts[0].description

print(string)

text_detection method expects an Cloud Vision Image task instance for analization, where you're passing Image 另一种类型的实例。

您可以将 OpenCV 图像实例转换为适合 google-视觉客户端方法的图像实例:

roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
success, encoded_image = cv2.imencode('.jpg', roi)
roi_image = encoded_image.tobytes()
roi_image = vision.types.Image(content=roi_image)
response = client.text_detection(image=roi_image)