完整项目地址
利用CNN卷积神经网络实现车牌识别(tensorflow)附完整项目代码_SOBE_rrr的博客-CSDN博客_基于卷积神经网络的车牌识别
运行效果:
代码段:CarWin.py
#所有界面的父亲:QWidget
from PyQt5.QtGui import QIcon, QPalette, QBrush, QPixmap
from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QPushButton, QLineEdit, QFileDialog, QMessageBox
import sys
from AIDeal import car_deal
from loadCNN import load_digitModel
from subPic import picDeal
class CarWin(QWidget):
def __init__(self):
#构造函数
super().__init__()
#创建需要的标签
self.setWindowTitle("车牌识别系统主界面") #设置标题
self.setFixedSize(560,600) #固定之村 #不允许进行拉伸
# self.resize(630,520) #尺寸
#设置左上角的Logo
self.setWindowIcon(QIcon("./img/comic.png"))
#设置背景
palatte=QPalette()
palatte.setBrush(self.backgroundRole(),QBrush( QPixmap("./img/background.jpg")))
self.setPalette(palatte)
self.openPicbtn=QPushButton("打开图片",self)
self.openPicbtn.setGeometry(40,130,200,30)
self.Cardivbtn=QPushButton("车牌分割",self)
self.Cardivbtn.setGeometry(40,230,200,30)
self.numrecbtn=QPushButton("车牌号码识别",self)
self.numrecbtn.setGeometry(310,230,200,30)
self.processbtn=QPushButton("AI车牌识别",self)
self.processbtn.setGeometry(40,330,200,30)
self.lineEditL=QLineEdit("",self)
self.lineEditL.setGeometry(40,430,200,30)
self.lineEditR=QLineEdit("",self)
self.lineEditR.setGeometry(310,430,200,30)
self.labup = QLabel("upLabel", self)
self.labup.setStyleSheet("color:white")
self.labup.setGeometry(280,80 ,260, 120)
self.labup.setPixmap(QPixmap("img/background.jpg").scaled(self.labup.size())) # 根据标签的大小去调整图片的显示
self.labdown = QLabel("downLabel", self)
self.labdown.setStyleSheet("color:white")
self.labdown.setGeometry(280,280,260, 120)
self.labdown.setPixmap(QPixmap("img/background.jpg").scaled(self.labdown.size())) # 根据标签的大小去调整图片的显示
#信号和槽
self.openPicbtn.clicked.connect(self.openPic)
self.Cardivbtn.clicked.connect(self.divPic)
self.numrecbtn.clicked.connect(self.dealDigit)
self.processbtn.clicked.connect(self.AItest)
def openPic(self): #打开图片
#返回图片的路径和图片类型
self.imgPath,img_type=QFileDialog.getOpenFileName(self,"选择文件","","*.png;*.jpg;*.jpeg;;")
#self.imgPath是图片的路径 填进去
self.labup.setPixmap(QPixmap(self.imgPath).scaled(self.labup.size())) # self.labPic.size()根据标签的大小去调整图片的显示
def divPic(self):
self.pic=picDeal(self.imgPath) #把图片的路径给它
QMessageBox.about(self,"提示内容","车牌字符已经已经分割完成")
def dealDigit(self):
#识别车牌:
#1.加载模型
#2.给图片信息
#3.识别的结果展示
self.digit=load_digitModel()
#修改编辑框的内容
self.lineEditL.setText("车牌号码为:"+self.digit)
def AItest(self):
#AI车牌识别
self.number=car_deal(self.imgPath) #路径是打开图片的路径
#将车牌区域框起来在图片上显示
self.labdown.setPixmap(QPixmap("./result.png").scaled(self.labdown.size()))
#将车牌结果在编辑框中显示
self.lineEditR.setText("车牌号码为:" + self.number)
if __name__ == '__main__':
app=QApplication(sys.argv) #应用程序
CarWindow=CarWin() #创建一个登陆窗口
CarWindow.show() #显示窗口
sys.exit(app.exec_())