齐紫荆。 发表于 2021-1-26 19:45:24

用python做车牌识别如何提高准确率

用python中的opencv 做的车牌识别,其中车牌提取准确率不是很高,有没有提高准确率的办法。
import cv2
from matplotlib import pyplot as plt

def cv2_show(name,image):
    cv2.imshow(name,img)
    cv2.waitKey()
    cv2.destroyAllWindows()

def plt_show0(img):
    b,g,r = cv2.split(img)
    img = cv2.merge()
    plt.imshow(img)
    plt.show()

def plt_show(img):
    plt.imshow(img,cmap="gray")
    plt.show()

rawImage = cv2.imread(r"C:\Users\86182\Desktop\biyesheji\chepai.png")
#plt_show0(rawImage)

#高斯去噪
image = cv2.GaussianBlur(rawImage,(3,3),0)
#plt_show0(image)

#灰度处理
gray_image = cv2.cvtColor(image,cv2.COLOR_RGB2GRAY)
#plt_show(gray_image)

#阈值处理
ret,image = cv2.threshold(gray_image,0,255,cv2.THRESH_OTSU)
#plt_show(image)

#黑白转换
area_white = 0
area_black = 0
height, width = image.shape
print(image.shape)
for i in range(height):
    for j in range(width):
      if image == 255:
            area_white += 1
      else:
            area_black += 1

if area_white>area_black:
    ret,image = cv2.threshold(gray_image,0,255,cv2.THRESH_OTSU | cv2.THRESH_BINARY_INV)
    plt_show(image)

kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(2,2))
image = cv2.dilate(image,kernel)
plt_show(image)

contours,hierarchy = cv2.findContours(image,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
image1 = rawImage.copy()
cv2.drawContours(image1,contours,-1,(0,0,255),1)
plt_show0(image1)

words = []
for item in contours:
    word = []
    rect = cv2.boundingRect(item)
    x = rect
    y = rect
    weight = rect
    height = rect
    word.append(x)
    word.append(y)
    word.append(weight)
    word.append(height)
    words.append(word)

word = sorted(words,key=lambda s:s,reverse=False)

print(words)
i = 0
for word in words:
    if (word>(word * 1.3)) and (word < (word * 3)):
      i = i + 1
      image = rawImage:word + word,word:word + word]
      #plt_show0(image)
      #cv2.imwrite(r"C:\Users\86182\Desktop\biyesheji\text " + str(i) + ".png",image)


小甲鱼的铁粉 发表于 2021-1-26 19:59:39

去AI Studio搜搜{:10_256:}

°蓝鲤歌蓝 发表于 2021-1-26 21:30:03

机器学习
页: [1]
查看完整版本: 用python做车牌识别如何提高准确率