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

标签 python ocr

亲爱的。 我将使用 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/

相关文章:

python - 为什么导入csv文件时要使用infer_datetime_format?

python - 高效的OCR微调

JavaScript OCR API

c# - 如何利用 tesseract 中所有可用的语言?

python - Plone 以轻量级方式存储表单输入

python - Plotly:如何处理金融时间序列的缺失日期?

Python 日志记录 StreamHandler 不从模块记录日志

Python pandas - 两行标题

c# - 如何从pdf图像中查找文本?

Python - 图像处理和光学字符阅读器