gpt4 book ai didi

python - 如何解决 python 中的 "data type = 19 is not supported"错误?

转载 作者:行者123 更新时间:2023-12-05 07:35:40 25 4
gpt4 key购买 nike

亲爱的。我将使用 python ocr 从图像中获取文本。我希望解决以下错误。我无法解决这个错误。代码和错误如下。谢谢。

    import pytesseract
from PIL import Image, ImageEnhance, ImageFilter
import cv2
import numpy as np


src_path = ""
def get_string(img_path):

#read image with opencv
img = cv2.imread(img_path)
#convert to gray
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#apply dilation and erosion to remove some noise
kernel = np.ones((1,1), np.unicode)
img = cv2.dilate(img, kernel, iterations=1)
img = cv2.erode(img, kernel, iterations=1)
cv2.imwrite("2.jpg", img)
#apply threshold to get image with only black and white
img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSAIN_C,
cv2.THRESH_BINARY,11,2)
cv2.imwrite("1.jpg", img)
#recognize text with tesseract for python
result = pytesseract.image_to_string(Image.open("1.jpg"))
return result
print(get_string("a.jpg"))

错误如下。

 C:\python\python.exe C:/Users/rharmed/PycharmProjects/nike/crawler2_.py
Traceback (most recent call last):
File "C:/Users/rharmed/PycharmProjects/nike/crawler2_.py", line 26, in
<module>
print(get_string("a.jpg"))
File "C:/Users/rharmed/PycharmProjects/nike/crawler2_.py", line 15, in
get_string
img = cv2.dilate(img, kernel, iterations=1)
TypeError: kernel data type = 19 is not supported
[ INFO:0] Initialize OpenCL runtime...

Process finished with exit code 1

最佳答案

您的内核不是有效的数据类型。

改变

kernel = np.ones((1,1), np.unicode)

kernel = np.ones((1,1), np.uint8)

关于python - 如何解决 python 中的 "data type = 19 is not supported"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49396631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com