gpt4 book ai didi

python - 车辆牌照 OCR

转载 作者:行者123 更新时间:2023-11-28 18:56:34 26 4
gpt4 key购买 nike

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 打印图像时得到的某种矩阵。

最佳答案

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

print(NumberPlateCnt)

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

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

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

Number Plate Detected

Number is :

[[[223 278]]

[[272 279]]

[[274 282]]

[[224 281]]]

“Number is:”字符串是空的,下一次等高线计算迭代将得出以下矩阵结果。

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

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

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

关于python - 车辆牌照 OCR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57622389/

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