基于python车牌号识别_如何用Python提取和识别车牌号?
作为一个初步的概念方案,在此基础之上你希望进行进一步的完善吗?建议您从图像中提取出车牌号码,并将其传输至您的Tesseract系统中进行处理。通过查看代码中的注释部分来更好地理解我的意图
import cv2
import pytesseract
import matplotlib.pyplot as plt
img = cv2.imread('/home/muthu/Documents/3r9OQ.jpg')
#convert my image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#carry out an automatic thresholding technique in order to allow me to extract accurate boundary outlines from the picture
#need this to extract the name plate from the image.
Assign a threshold value to the variable thresh by utilizing OpenCV's adaptive thresholding function with a Gaussian-based approach on the grayscale image. The parameters include a maximum value of 255, a block size of 11 pixels and a constant of 2 for variance.
contours,h = cv2.findContours(thresh,1,2)
Once I have obtained the outlines from the contours list, I will determine which of them form rectangles.
The contours can be approximated as minimum polygons. Four-sided polygons are likely to be rectangles.
largest_rectangle = [0,0]
for cnt in contours:
approx = cv2.approxPolyDP(cnt,0.01*cv2.arcLength(cnt,True),True)
if len(approx)==4: #polygons with 4 points is what I need.
area = cv2.contourArea(cnt)
if area > largest_rectangle[0]:
#find the polygon which has the largest size.
largest_rectangle = [cv2.contourArea(cnt), cnt, approx]
x,y,w,h = cv2.boundingRect(largest_rectangle[1])
#crop the rectangle to get the number plate.
roi=img[y:y+h,x:x+w]
#cv2.drawContours(img,[largest_rectangle[1]],0,(0,0,255),-1)
plt.imshow(roi, cmap = 'gray')
plt.show()
输出为牌照,如下所示:
现在把这个裁剪过的图像传给你的镶嵌画。在
^{pr2}$
下面是您共享的示例图像的输出。在
为了使车牌图像的透视转换呈现出边框矩形形状,并移除周围多余的边框后,在检测过程中所得结果会更加精确。如果您需要进一步的帮助,请随时告知我。
此代码不适合处理第二个图像,请考虑以下几点:因为当前筛选结果仅包含四边形,在这种情况下应用该代码可能会导致错误的结果。如能采纳此建议将不胜感激。
