|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
用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([r,g,b])
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[i,j] == 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[0]
y = rect[1]
weight = rect[2]
height = rect[3]
word.append(x)
word.append(y)
word.append(weight)
word.append(height)
words.append(word)
word = sorted(words,key=lambda s:s[0],reverse=False)
print(words)
i = 0
for word in words:
if (word[3]>(word[2] * 1.3)) and (word[3] < (word[2] * 3)):
i = i + 1
image = rawImage[word[1]:word[1] + word[3],word[0]:word[0] + word[2]]
#plt_show0(image)
#cv2.imwrite(r"C:\Users\86182\Desktop\biyesheji\text " + str(i) + ".png",image)
|
|