【问题标题】:Vehicle Registration Plate OCR车牌OCR
【发布时间】:2019-12-28 13:09:52
【问题描述】:

pyterresect 的最终调用不是返回字符串,而是仅返回该图像的每个像素的打印值。

import numpy as np
import cv2
import  imutils
from PIL import Image
from pytesseract import image_to_string

count = 0
for c in cnts:
        peri = cv2.arcLength(c, True)
        approx = cv2.approxPolyDP(c, 0.02 * peri, True)
        if len(approx) == 4:  # Select the contour with 4 corners
            NumberPlateCnt = approx #This is our approx Number Plate Contour
            pl=NumberPlateCnt
            print(NumberPlateCnt)
            if(pl[0][0][1]+10>pl[2][0][1] or pl[0][0][0]+40>pl[2][0][0]):
                continue
            filter_img = image[pl[0][0][1]:pl[2][0][1],pl[0][0][0]:pl[2][0][0]]
            print("Number Plate Detected")
            cv2_imshow(filter_img)

            Number=pytesseract.image_to_string(filter_img,lang='eng')
            print("Number is :",Number)
            cv2.waitKey(0)
            cv2.drawContours(image, [NumberPlateCnt], -1, (0, 255, 0), 3)

print("Final Image With Number Plate Detected")
cv2_imshow(image)

cv2.waitKey(0) #Wait for user input before closing the images displayed

我在这里得到的数字应该是一些字符串,但它的打印就像我们使用 print 打印图像时得到的某种矩阵一样。

【问题讨论】:

    标签: python python-3.x machine-learning artificial-intelligence


    【解决方案1】:

    你得到的矩阵很可能来自你的这行代码:

    print(NumberPlateCnt)
    

    pytesseract.image_to_string 只是无法识别您尝试获取的矩形轮廓上的任何文本,这意味着以下两行会打印出一个空结果:

    Number=pytesseract.image_to_string(filter_img,lang='eng')
    print("Number is :",Number)
    

    由于您正在对面积最大的轮廓进行迭代,因此输出应如下所示:

    检测到车牌

    数字是:

    [[[223 278]]

    [[272 279]]

    [[274 282]]

    [[224 281]]]

    “数字为:”字符串为空,以下矩阵结果来自轮廓计算的下一次迭代。

    要解决这个问题,您可以检查 PyTesseract 返回的字符串是否包含任何内容,如下所示:

       if (len(Number)):
           print("Number is :", Number)
    

    只有在其中包含 PyTesseract 识别的任何符号的情况下才会打印 Number。

    【讨论】:

    • 在这种情况下也打印相同的矩阵。但我传递给函数的图像只包含边界和字母数字。
    • 您能分享一个您正在尝试的图像示例吗?
    猜你喜欢
    • 1970-01-01
    • 2018-01-03
    • 2015-04-06
    • 2011-03-31
    • 2010-11-19
    • 1970-01-01
    • 2017-07-05
    • 2016-12-28
    • 1970-01-01
    相关资源
    最近更新 更多