python利用opencv对识别到的车牌号进行分割

import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
image=cv.imread("G:\\IDLE\\chepai.jpg")
img=cv.GaussianBlur(image.copy(),(5,5),9)
gray=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
ret,binary = cv.threshold(gray,0,255,cv.THRESH_BINARY+cv.THRESH_OTSU)
revImg=cv.bitwise_not(binary)    #二值图像取反
imgShape=revImg.shape
height=imgShape[0]
width=imgShape[1]
num=0
for i in range(height):       #去除图像周围的黑框
     for j in range(width):
          if 0<i<45 and revImg[i,j]==0:
               revImg[i,j]=255
          elif height-10<i<height and revImg[i,j]==0:
               revImg[i,j]=255
          elif (height-height/3)<i<height and 0<j<20 and revImg[i,j]==0:
               revImg[i,j]=255
          elif (height-height/3)<i<height and width-20<j<width and revImg[i,j]==0:
               revImg[i,j]=255
i=5
j=1
while num!=7:              #对车牌号进行分割
     #plt.subplot(1,7,j)
     if 2<=num<3:
          #plt.imshow(revImg[:,i:i+170])
          cv.imwrite("G:\\detect\\chepai"+str(j)+".jpg",revImg[:,i:i+170])
          #plt.xticks([])
          #plt.yticks([])
          i=i+170
     else:
          #plt.imshow(revImg[:,i:i+120])
          cv.imwrite("G:\\detect\\chepai"+str(j)+".jpg",revImg[:,i:i+120])
          #plt.xticks([])
          #plt.yticks([])
          i=i+120
     j=j+1
     num=num+1
#plt.show()
#cv.imshow("revImg",revImg)

python利用opencv对识别到的车牌号进行分割_第1张图片
python利用opencv对识别到的车牌号进行分割_第2张图片
python利用opencv对识别到的车牌号进行分割_第3张图片

你可能感兴趣的:(图像处理,车牌号识别,图像分割,opencv,车牌号分割,计算机视觉)