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打印图像时一样。