首页
学习
活动
专区
圈层
工具
发布

车牌OCR
EN

Stack Overflow用户
提问于 2019-08-23 16:25:00
回答 1查看 134关注 0票数 3

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

代码语言:javascript
复制
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打印图像时得到的某种矩阵一样。

EN

回答 1

Stack Overflow用户

发布于 2019-08-23 18:49:46

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

代码语言:javascript
复制
print(NumberPlateCnt)

而且pytesseract.image_to_string无法识别您正在尝试获取的矩形轮廓上的任何文本,这意味着以下两行代码将打印一个空结果:

代码语言:javascript
复制
Number=pytesseract.image_to_string(filter_img,lang='eng')
print("Number is :",Number)

由于您正在迭代具有最大面积的等高线,因此输出应如下所示:

检测到

车牌

编号为:

[[223 278]

[272279]

[274282]

[224 281]

"Number is:“字符串是空的,下面的矩阵结果来自轮廓线计算的下一次迭代。

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

代码语言:javascript
复制
   if (len(Number)):
       print("Number is :", Number)

只有当数字中包含PyTesseract可识别的任何符号时,它才会打印数字。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57622389

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档