[英]TypeError: get() expected a dict or protobuf message, got <class 'numpy.ndarray'>
I'm trying to take a region of a picture using OpenCV, and then extracting that text.我正在尝试使用 OpenCV 拍摄图片的一个区域,然后提取该文本。 Any idea how to fix this error?
知道如何解决此错误吗?
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 instance of another type. text_detection方法需要一个用于分析的 Cloud Vision Image任务实例,您将在其中传递另一种类型的Image实例。
You can convert OpenCV image instance to the one suitable for google-vision client methods:您可以将 OpenCV 图像实例转换为适合 google-vision 客户端方法的实例:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.