简体   繁体   English

TypeError: get() 期望一个 dict 或 protobuf 消息,得到<class 'numpy.ndarray'></class>

[英]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.

相关问题 TypeError:参数类型不正确(预期为 numpy.ndarray,得到 numpy.bool_) - TypeError: Argument has incorrect type (expected numpy.ndarray, got numpy.bool_) PyTorch - 获取 &#39;TypeError: pic 应该是 PIL Image 或 ndarray。 得到<class 'numpy.ndarray'> &#39; 错误 - PyTorch - Getting the 'TypeError: pic should be PIL Image or ndarray. Got <class 'numpy.ndarray'>' error 类型错误:预计 numpy.ndarray 或 cuda.ndarray - TypeError: numpy.ndarray or cuda.ndarray are expected 类型错误:img 应该是 PIL 图像。 得到<class 'numpy.ndarray'> - PyTorch</class> - TypeError: img should be PIL Image. Got <class 'numpy.ndarray'> - PyTorch TypeError:数据应该是LabeledPoint的RDD,但是得到了<type 'numpy.ndarray'> - TypeError: data should be an RDD of LabeledPoint, but got <type 'numpy.ndarray'> sklearn :: TypeError:参数n_values的类型错误。 预期的“自动”,整数或整数数组,得到了 <type 'numpy.ndarray'> - sklearn::TypeError: Wrong type for parameter `n_values`. Expected 'auto', int or array of ints, got <type 'numpy.ndarray'> TypeError:DataLoader 发现无效类型:<class 'numpy.ndarray'></class> - TypeError: DataLoader found invalid type: <class 'numpy.ndarray'> AssertionError: HybridBlock 需要第一个参数来转发是 Symbol 或 NDArray,但得到<class 'numpy.ndarray'> - AssertionError: HybridBlock requires the first argument to forward be either Symbol or NDArray, but got <class 'numpy.ndarray'> TypeError:无法散列的类型:&#39;numpy.ndarray&#39;mnist - TypeError: unhashable type: 'numpy.ndarray' mnist 类型错误:不可散列类型:&#39;numpy.ndarray&#39; - TypeError: unhashable type: 'numpy.ndarray'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM