Together with Python to do a license plate automatic recognition system, fun and practical!

Python The column contains this content
30 articles 108 subscriptions

preface

Some time ago, I wrote two articles with pyqt5 aboutPython made a cool music playerCustom desktop animation Pendant。 Some fans asked me, why use pyqt5? I haven't contacted pyqt5 before. Can you share more development cases in this regard?

Today, I will continue to share with you a practical case and take you to develop an automatic license plate recognition system with pyqt5 of Python!

First, let's take a look at the rendering of the finally realized license plate recognition system:Insert picture description here
Next, we will begin to introduce how to implement this automatic license plate recognition system.

1、 Core function design

Generally speaking, we should first design the UI interface, and make the screen layout according to the functions of the license plate recognition system; Secondly, the main functions of our license plate recognition system are vehicle picture reading, recognition and display, license plate ROI area acquisition in the picture, and license plate recognition result output and display.

For the result output display, we mainly include reading the picture name, reading the input time, identifying the license plate number, identifying the license plate color and identifying the license plate location. Finally, we can export the data information of the license plate recognition system to local storage.

According to the disassembly requirements, the core functions can be roughly sorted out as follows:

  • UI design layout

    • The left area displays the identification information, including picture name, reading and entry time, license plate number recognition, license plate color recognition and license plate ownership information
    • The right side can be divided into three areas. The top area contains the functions of minimizing, maximizing and closing the form; The middle area displays the read vehicle picture; The bottom area includes license plate display area, picture reading and license plate information storage functions
  • License plate recognition

    • Extract and output the license plate area by reading the picture
    • Automatic license plate recognition result output
  • License plate information display and storage

    • Display all kinds of license plate information according to the automatic recognition results
    • Store the vehicle license plate recognition information entered for recognition

2、 Implementation steps

1. UI design and layout

According to the functions required for license plate recognition, firstUI layout design, we still use it this timepyqt5。 The core design code is as follows:

#Author: CSDN dragon juvenile
def setupUi(self,MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(one thousand two hundred and thirteen, six hundred and seventy)
MainWindow.setFixedSize(one thousand two hundred and thirteen, six hundred and seventy)  #Set form fixed size
MainWindow.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
self.centralwidget =QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.scrollArea =QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setGeometry(QtCore.QRect(six hundred and ninety, forty, five hundred and eleven, four hundred and sixty))
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents =QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, five hundred, four hundred and eighty-nine))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.label_ 0=QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_ 0.setGeometry(QtCore.QRect(ten, ten, one hundred and eleven, twenty))
font =QtGui.QFont()
font.setPointSize(eleven)
self.label_ 0.setFont(font)
self.label_ 0.setObjectName("label_ 0")
self.label =QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label.setGeometry(QtCore.QRect(ten, forty, four hundred and eighty-one, four hundred and twenty))
self.label.setObjectName("label")
self.label.setAlignment(Qt.AlignCenter)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.scrollArea_ two=QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea_ two.setGeometry(QtCore.QRect(ten, ten, six hundred and seventy-one, six hundred and thirty-one))
self.scrollArea_ two.setWidgetResizable(True)
self.scrollArea_ two.setObjectName("scrollArea_ 2")
self.scrollAreaWidgetContents_ one=QtWidgets.QWidget()
self.scrollAreaWidgetContents_ one.setGeometry(QtCore.QRect(0, 0, six hundred and sixty-nine, six hundred and twenty-nine))
self.scrollAreaWidgetContents_ one.setObjectName("scrollAreaWidgetContents_ 1")
self.label_ one=QtWidgets.QLabel(self.scrollAreaWidgetContents_ one)
self.label_ one.setGeometry(QtCore.QRect(ten, ten, one hundred and eleven, twenty))
font =QtGui.QFont()
font.setPointSize(eleven)
self.label_ one.setFont(font)
self.label_ one.setObjectName("label_ 1")
self.tableWidget =QtWidgets.QTableWidget(self.scrollAreaWidgetContents_ one)
self.tableWidget.setGeometry(QtCore.QRect(ten, forty, six hundred and fifty-one, five hundred and eighty-one))  # 581))
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(five)
self.tableWidget.setColumnWidth(0, one hundred and forty)  #Set the width of column 1
self.tableWidget.setColumnWidth(one, one hundred and thirty)  #Sets the width of the 2 columns
self.tableWidget.setColumnWidth(two, one hundred and ten)  #Sets the width of the 3 columns
self.tableWidget.setColumnWidth(three, ninety)  #Sets the width of the 4 columns
self.tableWidget.setColumnWidth(four, one hundred and eighty-one)  #Set the width of 5 columns
self.tableWidget.setHorizontalHeaderLabels(["Picture name", "Entry time", "License plate number", "License plate type", "License plate information"])
self.tableWidget.setRowCount(self.RowLength)
self.tableWidget.verticalHeader().setVisible(False)  #Hide vertical header)
self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.tableWidget.raise_()
self.scrollArea_ two.setWidget(self.scrollAreaWidgetContents_ one)
self.scrollArea_ three=QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea_ three.setGeometry(QtCore.QRect(six hundred and ninety, five hundred and ten, three hundred and forty-one, one hundred and thirty-one))
self.scrollArea_ three.setWidgetResizable(True)
self.scrollArea_ three.setObjectName("scrollArea_ 3")
self.scrollAreaWidgetContents_ three=QtWidgets.QWidget()
self.scrollAreaWidgetContents_ three.setGeometry(QtCore.QRect(0, 0, three hundred and thirty-nine, one hundred and twenty-nine))
self.scrollAreaWidgetContents_ three.setObjectName("scrollAreaWidgetContents_ 3")
self.label_ two=QtWidgets.QLabel(self.scrollAreaWidgetContents_ three)
self.label_ two.setGeometry(QtCore.QRect(ten, ten, one hundred and eleven, twenty))
font =QtGui.QFont()
font.setPointSize(eleven)
self.label_ two.setFont(font)
self.label_ two.setObjectName("label_ 2")
self.label_ three=QtWidgets.QLabel(self.scrollAreaWidgetContents_ three)
self.label_ three.setGeometry(QtCore.QRect(ten, forty, three hundred and twenty-one, eighty-one))
self.label_ three.setObjectName("label_ 3")
self.scrollArea_ three.setWidget(self.scrollAreaWidgetContents_ three)
self.scrollArea_ four=QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea_ four.setGeometry(QtCore.QRect(one thousand and forty, five hundred and ten, one hundred and sixty-one, one hundred and thirty-one))
self.scrollArea_ four.setWidgetResizable(True)
self.scrollArea_ four.setObjectName("scrollArea_ 4")
self.scrollAreaWidgetContents_ four=QtWidgets.QWidget()
self.scrollAreaWidgetContents_ four.setGeometry(QtCore.QRect(0, 0, one hundred and fifty-nine, one hundred and twenty-nine))
self.scrollAreaWidgetContents_ four.setObjectName("scrollAreaWidgetContents_ 4")
self.pushButton_ two=QtWidgets.QPushButton(self.scrollAreaWidgetContents_ four)
self.pushButton_ two.setGeometry(QtCore.QRect(twenty, fifty, one hundred and twenty-one, thirty-one))
self.pushButton_ two.setObjectName("pushButton_ 2")
self.pushButton =QtWidgets.QPushButton(self.scrollAreaWidgetContents_ four)
self.pushButton.setGeometry(QtCore.QRect(twenty, ninety, one hundred and twenty-one, thirty-one))
self.pushButton.setObjectName("pushButton")
self.label_ four=QtWidgets.QLabel(self.scrollAreaWidgetContents_ four)
self.label_ four.setGeometry(QtCore.QRect(ten, ten, one hundred and eleven, twenty))
font =QtGui.QFont()
font.setPointSize(eleven)
self.label_ four.setFont(font)
self.label_ four.setObjectName("label_ 4")
self.scrollArea_ four.setWidget(self.scrollAreaWidgetContents_ four)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar =QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.pushButton.clicked.connect(self.__ openimage)  #Set click event
self.pushButton.setStyleSheet('''QPushButton{background:#222225; border-radius:5px;} QPushButton:hover{background:#2B2B2B;}''')
self.pushButton_ two.clicked.connect(self.__ writeFiles)  #Set click event
self.pushButton_ two.setStyleSheet('''QPushButton{background:#222225; border-radius:5px;} QPushButton:hover{background:#2B2B2B;}''')
self.retranslateUi(MainWindow)
self.close_ widget =QtWidgets.QWidget(self.centralwidget)
self.close_ widget.setGeometry(QtCore.QRect(one thousand one hundred and thirty, 0, ninety, fifty))
self.close_ widget.setObjectName("close_ widget")
self.close_ layout =QGridLayout()  #Create a grid layout layer for the left part
self.close_ widget.setLayout(self.close_ layout)  #Set the layout of the left part as a grid
self.left_ close =QPushButton("")  #Close button
self.left_ close.clicked.connect(self.close)
self.left_ visit =QPushButton("")  #Blank button
self.left_ visit.clicked.connect(MainWindow.big)
self.left_ mini =QPushButton("")  #Minimize button
self.left_ mini.clicked.connect(MainWindow.mini)
self.close_ layout.addWidget(self.left_ mini, 0, 0, one, one)
self.close_ layout.addWidget(self.left_ close, 0, two, one, one)
self.close_ layout.addWidget(self.left_ visit, 0, one, one, one)
self.left_ close.setFixedSize(fifteen, fifteen)  #Sets the size of the close button
self.left_ visit.setFixedSize(fifteen, fifteen)  #Set button size
self.left_ mini.setFixedSize(fifteen, fifteen)  #Set minimize button size
self.left_ close.setStyleSheet(
        '''QPushButton{background:#F76677; border-radius:5px;} QPushButton:hover{background:red;}''')
self.left_ visit.setStyleSheet(
        '''QPushButton{background:#F7D674; border-radius:5px;} QPushButton:hover{background:yellow;}''')
self.left_ mini.setStyleSheet(
        '''QPushButton{background:#6DDF6D; border-radius:5px;} QPushButton:hover{background:green;}''')

QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.ProjectPath =os.getcwd()  #Get the current project file location
self.scrollAreaWidgetContents.setStyleSheet(sc)
self.scrollAreaWidgetContents_ three.setStyleSheet(sc)
self.scrollAreaWidgetContents_ four.setStyleSheet(sc)
b =             '''
color:white;
background:#2B2B2B;
'''
self.label_ 0.setStyleSheet(b)
self.label_ one.setStyleSheet(b)
self.label_ two.setStyleSheet(b)
self.label_ three.setStyleSheet(b)
MainWindow.setWindowOpacity(zero point nine five)  #Set window transparency
MainWindow.setAttribute(Qt.WA_ TranslucentBackground)
MainWindow.setWindowFlag(Qt.FramelessWindowHint)  #Hide border

#Author: CSDN dragon juvenile
def retranslateUi(self,MainWindow):
_ translate =QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_ translate("MainWindow", "License plate recognition system"))
self.label_ 0.setText(_ translate("MainWindow", Original picture:))
self.label.setText(_ translate("MainWindow", ""))
self.label_ one.setText(_ translate("MainWindow", Recognition result:))
self.label_ two.setText(_ translate("MainWindow", License plate area:))
self.label_ three.setText(_ translate("MainWindow", ""))
self.pushButton.setText(_ translate("MainWindow", Open file))
self.pushButton_ two.setText(_ translate("MainWindow", Export data))
self.label_ four.setText(_ translate("MainWindow", Event:))
self.scrollAreaWidgetContents_ one.show()

The UI implementation effect is as follows:
Insert picture description here

2. License plate recognition

Next, we need to implement two core functions, including acquisitionLicense plate ROI areaandAutomatic license plate recognitionFunction.

License plate ROI region extraction:

According to the read vehicle image, preprocess to extract the ROI area of the license plate, mainly through the relevant knowledge points of OpenCV image processing. It mainly includes image denoising, binarization, edge contour extraction, rectangular region correction, blue, green and yellow license plate color location and recognition. The core code is as follows:

#Author: CSDN dragon juvenile
#Pretreatment
def pretreatment(self,car_ pic):
    if type(car_ pic) == type(""):
img =self.__ imreadex(car_ pic)
    else:
img =car_ pic
pic_ hight,pic_ width =img.shape[:two]

    ifpic_ width >self.MAX_ WIDTH:
resize_ rate =self.MAX_ WIDTH /pic_ width
img =cv2.resize(img, (self.MAX_ WIDTH, int(pic_ hight *resize_ rate)),
interpolation=cv2.INTER_ AREA)  #Picture resolution adjustment
blur =self.cfg["blur"]
    #Gaussian denoising
    ifblur > 0:
img =cv2.GaussianBlur(img, (blur,blur), 0)
oldimg =img
img =cv2.cvtColor(img,cv2.COLOR_ BGR2GRAY)
kernel =np.ones((twenty, twenty),np.uint8)
img_ opening =cv2.morphologyEx(img,cv2.MORPH_ OPEN,kernel)  #Open operation
img_ opening =cv2.addWeighted(img, one,img_ opening, -one, 0);  #Fusion with the result of the last open operation
    # cv2.imshow('img_ opening', img_ opening)

    #Find image edge
ret,img_ thresh =cv2.threshold(img_ opening, 0, two hundred and fifty-five,cv2.THRESH_ BINARY +cv2.THRESH_ OTSU)  #Binarization
img_ edge =cv2.Canny(img_ thresh, one hundred, two hundred)
    # cv2.imshow('img_ edge', img_ edge)

    #Use open and close operations to make the image edge a whole
kernel =np.ones((self.cfg["morphologyr"],self.cfg["morphologyc"]),np.uint8)
img_ edge1 =cv2.morphologyEx(img_ edge,cv2.MORPH_ CLOSE,kernel)  #Closed operation
img_ edge2 =cv2.morphologyEx(img_ edge1,cv2.MORPH_ OPEN,kernel)  #Open operation
    # cv2.imshow('img_ edge2', img_ edge2)
    # cv2.imwrite('./edge2.png', img_ edge2)
    #Find the rectangular area formed by the overall edge of the image, there may be many, and the license plate is in one of the rectangular areas
image,contours,hierarchy =cv2.findContours(img_ edge2,cv2.RETR_ TREE,cv2.CHAIN_ APPROX_ SIMPLE)
contours = [cnt forcnt incontours ifcv2.contourArea(cnt) >self.Min_ Area]
    #Exclude rectangular areas that are not license plates one by one
car_ contours = []
    forcnt incontours:
        #Box select to generate the minimum circumscribed rectangle return value (Center (x, y), (width, height), rotation angle)
rect =cv2.minAreaRect(cnt)
        #Print ('width height: ', rect [1])
area_ width,area_ height =rect[one]
        #Select an area whose width is greater than its height
        ifarea_ width <area_ height:
area_ width,area_ height =area_ height,area_ width
wh_ ratio =area_ width /area_ height
        #Print ('aspect ratio: ', wh_ ratio)
        #The aspect ratio of rectangular area is required to be between 2 and 5.5. 2 to 5.5 is the aspect ratio of license plate, and other rectangles are excluded
        ifwh_ ratio > two andwh_ ratio < five point five:
car_ contours.append(rect)
box =cv2.boxPoints(rect)
box =np.int0(box)
    #The rectangular area may be an inclined rectangle and needs to be corrected in order to use color positioning
card_ imgs = []
    forrect incar_ contours:
        ifrect[two] > -one andrect[two] < one:  #Create angles so that left, high, right and low get the correct values
angle = one
        else:
angle =rect[two]
rect = (rect[0], (rect[one][0] + five,rect[one][one] + five),angle)  #Expand the scope to avoid the edge of the license plate being excluded
box =cv2.boxPoints(rect)
heigth_ point =right_ point = [0, 0]
left_ point =low_ point = [pic_ width,pic_ hight]
        forpoint inbox:
            ifleft_ point[0] >point[0]:
left_ point =point
            iflow_ point[one] >point[one]:
low_ point =point
            ifheigth_ point[one] <point[one]:
heigth_ point =point
            ifright_ point[0] <point[0]:
right_ point =point
        ifleft_ point[one] <=right_ point[one]:  #Positive angle
new_ right_ point = [right_ point[0],heigth_ point[one]]
pts2 =np.float32([left_ point,heigth_ point,new_ right_ point])  #The characters just need to be changed in height
pts1 =np.float32([left_ point,heigth_ point,right_ point])
M =cv2.getAffineTransform(pts1,pts2)
dst =cv2.warpAffine(oldimg,M, (pic_ width,pic_ hight))
self.__ point_ limit(new_ right_ point)
self.__ point_ limit(heigth_ point)
self.__ point_ limit(left_ point)
card_ img =dst[int(left_ point[one]):int(heigth_ point[one]), int(left_ point[0]):int(new_ right_ point[0])]
card_ imgs.append(card_ img)

        elifleft_ point[one] >right_ point[one]:  #Negative angle

new_ left_ point = [left_ point[0],heigth_ point[one]]
pts2 =np.float32([new_ left_ point,heigth_ point,right_ point])  #The characters just need to be changed in height
pts1 =np.float32([left_ point,heigth_ point,right_ point])
M =cv2.getAffineTransform(pts1,pts2)
dst =cv2.warpAffine(oldimg,M, (pic_ width,pic_ hight))
self.__ point_ limit(right_ point)
self.__ point_ limit(heigth_ point)
self.__ point_ limit(new_ left_ point)
card_ img =dst[int(right_ point[one]):int(heigth_ point[one]), int(new_ left_ point[0]):int(right_ point[0])]
card_ imgs.append(card_ img)
    #Use color location to exclude rectangles that are not license plates. At present, only blue, green and yellow license plates are recognized
colors = []
    forcard_ index,card_ img in enumerate(card_ imgs):
green =yellow =blue =black =white = 0
        try:
            #There is a possibility of conversion failure due to the above error
card_ img_ hsv =cv2.cvtColor(card_ img,cv2.COLOR_ BGR2HSV)
        except:
            print('BGR to HSV failed')
card_ imgs =colors = None
            returncard_ imgs,colors

        ifcard_ img_ hsv is None:
            continue
row_ num,col_ num =card_ img_ hsv.shape[:two]
card_ img_ count =row_ num *col_ num

        #Determine license plate color
        fori in range(row_ num):
            forj in range(col_ num):
H =card_ img_ hsv.item(i,j, 0)
S =card_ img_ hsv.item(i,j, one)
V =card_ img_ hsv.item(i,j, two)
                if eleven <H <= thirty-four andS > thirty-four:  #Picture resolution adjustment
yellow += one
                elif thirty-five <H <= ninety-nine andS > thirty-four:  #Picture resolution adjustment
green += one
                elif ninety-nine <H <= one hundred and twenty-four andS > thirty-four:  #Picture resolution adjustment
blue += one

                if 0 <H < one hundred and eighty and 0 <S < two hundred and fifty-five and 0 <V < forty-six:
black += one
                elif 0 <H < one hundred and eighty and 0 <S < forty-three and two hundred and twenty-one <V < two hundred and twenty-five:
white += one
color = "no"
        #Print ('yellow: {: < 6} green: {: < 6} blue: {: < 6} '. Format (yellow, green, blue))

limit1 =limit2 = 0
        ifyellow * two >=card_ img_ count:
color = "yellow"
limit1 = eleven
limit2 = thirty-four  #Some pictures are colored green
        elifgreen * two >=card_ img_ count:
color = "green"
limit1 = thirty-five
limit2 = ninety-nine
        elifblue * two >=card_ img_ count:
color = "blue"
limit1 = one hundred
limit2 = one hundred and twenty-four  #Some pictures are purple in color
        elifblack +white >=card_ img_ count * zero point seven:
color = "bw"
        # print(color)
colors.append(color)
        # print(blue, green, yellow, black, white, card_ img_ count)
        iflimit1 == 0:
            continue

        #Reposition according to the license plate color to reduce the edge and non license plate boundary
xl,xr,yh,yl =self.accurate_ place(card_ img_ hsv,limit1,limit2,color)
        ifyl ==yh andxl ==xr:
            continue
need_ accurate = False
        ifyl >=yh:
yl = 0
yh =row_ num
need_ accurate = True
        ifxl >=xr:
xl = 0
xr =col_ num
need_ accurate = True
card_ imgs[card_ index] =card_ img[yl:yh,xl:xr]\
            ifcolor != "green" oryl < (yh -yl) // four elsecard_ img[yl - (yh -yl) // four:yh,xl:xr]
        ifneed_ accurate:  #The X or Y direction may not shrink. You need to try again
card_ img =card_ imgs[card_ index]
card_ img_ hsv =cv2.cvtColor(card_ img,cv2.COLOR_ BGR2HSV)
xl,xr,yh,yl =self.accurate_ place(card_ img_ hsv,limit1,limit2,color)
            ifyl ==yh andxl ==xr:
                continue
            ifyl >=yh:
yl = 0
yh =row_ num
            ifxl >=xr:
xl = 0
xr =col_ num
card_ imgs[card_ index] =card_ img[yl:yh,xl:xr]\
            ifcolor != "green" oryl < (yh -yl) // four elsecard_ img[yl - (yh -yl) // four:yh,xl:xr]
    # cv2.imshow("result", card_ imgs[0])
    # cv2.imwrite('1.jpg', card_ imgs[0])
    #Print ('color recognition result: '+ colors [0])
    returncard_ imgs,colors

At this point, we can output the ROI area and color of the license plate. The effect is as follows:
Insert picture description here
Automatic license plate recognition:

The license plate recognition blogger has written a recognition system based on OpenCV and SVM. Because the code is long, this article will not show it(Interested bloggers can get the source code)。 This article introduces how to call the information provided by Baidu AILicense plate recognition interfaceBaidu AI open platform link, the recognition effect is also very good.
Insert picture description here
Here we can create a license plate recognition application, in whichAPI key and secret keyWe will use it later when calling the license plate recognition and detection interface.
Insert picture description here
We can see the official help document, which describes how toCall the request URL data format and send the request to the API service address using post, you must take a parameter in the URLaccess_ token, which can be generated through the API key and secret key in the background. The API key and secret key mentioned above.
Insert picture description here
Next, let's take a look at the code example of calling the license plate recognition interface.
Insert picture description here
How do we get the recognized license plate number? You can see in the API document that there is awords_ Result dictionary , of whichColor stands for the license plate color Number stands for the license plate number 。 So I can know the recognized license plate color and license plate number.

Insert picture description here
The interface calling process of license plate recognition is basically clear, and the code implementation can be carried out below.

#Author: CSDN dragon juvenile
def get_ token(self):
host = ' https://aip.baidubce.com/oauth/2.0/token?grant_ type=client_ credentials&client_ id=' +self.client_ id + '&client_ secret=' +self.client_ secret
response =requests.get(host)
    ifresponse:
token_ info =response.json()
token_ key =token_ info['access_ token']
    returntoken_ key

#Author: CSDN dragon juvenile
def get_ license_ plate(self,car_ pic):
result = {}
card_ imgs,colors =self.pretreatment(car_ pic)
request_ url = " https://aip.baidubce.com/rest/2.0/ocr/v1/license_ plate"
    #Open picture file in binary mode
f = open(car_ pic, 'rb')
img =base64.b64encode(f.read())
params = {"image":img}
access_ token =self.get_ token()
request_ url =request_ url + "? access_ token=" +access_ token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response =requests.post(request_ url,data=params,headers=headers)
    ifresponse:
        print(response.json())
license_ result =response.json()['words_ result']['number']
card_ color =response.json()['words_ result']['color']
        iflicense_ result != []:
result['InputTime'] =time.strftime("%Y-%m-%d %H:%M:%S")
result['Type'] =self.cardtype[card_ color]
result['Picture'] =card_ imgs[0]
result['Number'] = ''.join(license_ result[:two]) + '·' + ''.join(license_ result[two:])
            try:
result['From'] = ''.join(self.Prefecture[license_ result[0]][license_ result[one]])
            except:
result['From'] = 'unknown'
            returnresult
    else:
        return None

In this way, we can get the license plate color and number. The effect is as follows:

Insert picture description here

3. Display and storage of license plate information

3.1 license plate information display:
#Author: CSDN dragon juvenile
def __ show(self,result,FileName):
    #Display table
self.RowLength =self.RowLength + one
    ifself.RowLength > eighteen:
self.tableWidget.setColumnWidth(five, one hundred and fifty-seven)
self.tableWidget.setRowCount(self.RowLength)
self.tableWidget.setItem(self.RowLength - one, 0,QTableWidgetItem(FileName))
self.tableWidget.setItem(self.RowLength - one, one,QTableWidgetItem(result['InputTime']))
self.tableWidget.setItem(self.RowLength - one, two,QTableWidgetItem(result['Number']))
self.tableWidget.setItem(self.RowLength - one, three,QTableWidgetItem(result['Type']))
    ifresult['Type'] == 'Blue license plate':
self.tableWidget.item(self.RowLength - one, three).setBackground(QBrush(QColor(three, one hundred and twenty-eight, two hundred and fifty-five)))
    elifresult['Type'] == 'green license plate':
self.tableWidget.item(self.RowLength - one, three).setBackground(QBrush(QColor(ninety-eight, one hundred and ninety-eight, one hundred and forty-eight)))
    elifresult['Type'] == 'yellow license plate':
self.tableWidget.item(self.RowLength - one, three).setBackground(QBrush(QColor(two hundred and forty-two, two hundred and two, nine)))
self.tableWidget.setItem(self.RowLength - one, four,QTableWidgetItem(result['From']))
self.tableWidget.item(self.RowLength - one, four).setBackground(QBrush(QColor(two hundred and fifty-five, two hundred and fifty-five, two hundred and fifty-five)))
    #Display the recognized license plate position
size = (int(self.label_ three.width()), int(self.label_ three.height()))
shrink =cv2.resize(result['Picture'],size,interpolation=cv2.INTER_ AREA)
shrink =cv2.cvtColor(shrink,cv2.COLOR_ BGR2RGB)
self.QtImg =QtGui.QImage(shrink[:],shrink.shape[one],shrink.shape[0],shrink.shape[one] * three,
QtGui.QImage.Format_ RGB888)
self.label_ three.setPixmap(QtGui.QPixmap.fromImage(self.QtImg))

The effects are as follows:
Insert picture description here

3.2 information export and storage:
#Author: CSDN dragon juvenile
def __ writexls(self,DATA,path):
wb =xlwt.Workbook();
ws =wb.add_ sheet('Data');
    #Data.insert (0, ['file name', 'entry time', 'license plate number', 'license plate type', 'license plate information'])
    fori,Data in enumerate(DATA):
        forj,data in enumerate(Data):
ws.write(i,j,data)
wb.save(path)
QMessageBox.information(None, "Success", "Data saved!",QMessageBox.Yes)
def __ writecsv(self,DATA,path):
f = open(path, 'w')
    #Data.insert (0, ['file name', 'entry time', 'license plate number', 'license plate type', 'license plate information'])
    fordata inDATA:
f.write((',').join(data) + '\n')
f.close()
QMessageBox.information(None, "Success", "Data saved!",QMessageBox.Yes)

def __ writeFiles(self):
path,filetype =QFileDialog.getSaveFileName(None, Save as,self.ProjectPath,
                                                 "Excel Workbook (*. XLS);; CSV (comma separated) (*. CSV)“)
    ifpath == "":  #Not selected
        return
    iffiletype == 'excel Workbook (*. XLS)':
self.__ writexls(self.Data,path)
    eliffiletype == 'CSV (comma separated) (*. CSV)':
self.__ writecsv(self.Data,path)

The effects are as follows:
Insert picture description here
The exported license plate information data is as follows:
Insert picture description here
So far, the whole automatic license plate recognition system has been completed ~ we'll stop here today and continue our efforts tomorrow!
Insert picture description here
If the content of this article is helpful to you, please like it three times, pay attention and collect it with support.

Creation is not easy, white whoring is not good. Your support and recognition is the biggest driving force for my creation. See you in the next article!

Dragon youth

If there are any mistakes in this blog, please comment and advice. Thank you very much!

<p>Master the technology based on Tencent artificial intelligence (AI)License plate recognitionTechnology, useLicense plate recognitionTechnology to achieve a complete parking lot managementsystemThe project includes calling the camera to take photos on the web page,License platePhoto identification, uploadLicense plateImage recognition, user management, vehicle management (temporary vehicle and monthly vehicle), vehicle exit, admission management, parking fee management, and parking fee is automatically calculated according to temporary vehicle or monthly vehicle,systemParameter setting, user password modification and safe exitsystemIt is realized by using JSP technology, SSM framework, MySQL database, AJAX technology, artificial intelligence and other related technologies</ p> <h2><span style="color: #e03e2d;"> Important notice: This course is based on Tencent AILicense plate recognitionNew interface, updated the source code of the new interface and released the program. Students who have purchased the course can download the new program, including (running program and source code). Update time: 2021-2-17 < / span > < br / > < br / > < span style = "color: #e53333;" > Project development technology: Java, JSP, mysql, mybatis, spring MVC, jQuery, AJAX, JSON < / span > < br / > < span style = "color: #e53333;" > Project running environment: jdk1.7 and above, tomcat6.0 and above, mysql5.5 and above < / span > < br / > < span style = "color: #e53333;" > Project development tool: the project development tool is eclipse, which also supports other versions of development tools such as MyEclipse and IntelliJ idea < / span > < br / > < br / ></h2> <p style="color: #333333;">< span style="font-size: 20px;">< span style="color: #ff0000;">< Strong > learning sequence of related courses < / strong > < / span > < / span ></p> <p style="color: #333333;"> Our courses are a complete set of courses to train Java software engineers, JSP Web application development and Android engineers. The learning order of the courses is as follows: < br / > < span style = "color: #ff0000;" >< Strong > java Junior Engineer: < / strong > < / span > < br / > 1. Computer foundation < br / > 2. HTML language foundation < br / > 3. C language from entry to mastery + Snake game < br / > 4. Snake game < br / > 5. SQL Server database foundation < br / > 6. Java from entry to mastery + push box game + QQ instant messaging software < br / > 7. Push box game< Br / > 8. Imitation QQ instant messaging software< br /><span style="color: #ff0000;">< Strong > java intermediate Engineer: < / strong > < / span > < br / > 9. SQLSERVER database advanced < br / > 10. Sqlserver from entry to mastery (Basic + Advanced) < br / > 11. JavaScript from entry to mastery, < br / > 12. JSP from entry to mastery + orderingsystem, < br / > 13. JSP from entry to mastery + online video learning education platform, < br / > 14. JSP from entry to mastery + large e-commerce platform< Br / > 15. XML from entry to mastery, < br / > 16. Data structure (Java version), < br / > < span style = "color: #ff0000;" >< Strong > Senior Java Engineer: < / strong > < / span > < br / > 17. Oracle database from entry to mastery, < br / > 18. Ajax + jQuery from entry to mastery, < br / > 19. EasyUI from entry to mastery, < br / > < span style = "color: #ff0000;" >< Strong > SSH Framework: < / strong > < / span > < br / > 20. Struts 2 from introductory to proficient courses, < br / > 21. Hibernate from introductory to proficient courses, < br / > 22. Spring from introductory to proficient courses< Br / > 23. Echarts from entry to mastery, < br / > 24. Excel POI based import and export < br / > < span style = "color: #ff0000;" >< Strong > workflow framework: < / strong > < / span > < br / > 25. Activiti process framework from entry to mastery < br / > 26. JBPM process framework from entry to mastery < br / > < span style = "color: #ff0000;" >< Strong > SSM framework: < / strong > < / span > < br / > 27. Mybatis from entry to mastery < br / > 28. Spring MVC from entry to mastery < br / > < span style = "color: #ff0000;" >< Strong > interview questions: < / strong > < / span > < br / > 29. Career planning and interview questions collection < br / > < span style = "color: #ff0000;" >< Strong> business projects: </strong></span><br / > 30, WeChat official account online paymentsystem< br / > 31. Wechat life payment online paymentsystem<br / > 32, Alipay life payment online paymentsystem< br / > 33. Online examinationsystem< br / > 34. Mobile ordering managementsystem, < br / > 35. CRM Customer Relationship Managementsystem< br / > 36. CRM sales management of large real estatesystem< br / > 37. Cmpp2, cmpp3 mobile gatewaysystem<br /><span style="color: #ff0000;">< Strong > Artificial Intelligence: < / strong > < / span > < br / > 38. Face recognition online examinationsystem< br / > 39. Face recognitionsystemProject practice < br / > 40License plate recognitionsystemProject practice < br / > 41. ID card identificationsystemProject practice < br / > 42. Business license identificationsystemProject practice</p> <p style="color: #333333;"> 43. Business card identification managementsystem</p>
<p> <strong><span style="font-size:16px; color:#337FE5;">< b><a target="_ blank" href=" http://prog3.com/sbdm/edu/bundled/detail/308 "></a><a target="_ blank" href=" http://prog3.com/sbdm/edu/bundled/detail/308 "><span> </span></a></b></span></strong> </p> <p class="ql-long-39788408" style="font-size:11pt; color:#494949;"> <strong><b><strong><a class="ql-link ql-size-12 ql-author-39788408" href=" http://prog3.com/sbdm/edu/bundled/detail/298 " target="_ Blank "> [this course belongs to the complete AI learning route package, which has been" hard core "online. Click to learn now!]</ a></strong> </b></strong> </p> <p class="ql-long-39788408" style="font-size:11pt; color:#494949;"> <br /> </p> <p> <strong><span style="font-size:16px; color:#337FE5;">< img src=" https://img-bss.csdnimg.cn/202011090216454206.png " alt="" /><br /> </span></strong> </p> <p> <strong><span style="font-size:16px; color:#337FE5;">< br /> </span></strong> </p> <p> <strong><span style="font-size:16px; color:#337FE5;">【 Why study deep learning and computer vision?]</ span></strong> </p> <p> <span style="font-family:"background-color:#FFFFFF;"> Ai artificial intelligence has now become the hottest field in human development. Computer vision (CV) is the most popular and landing application direction in AI < span style = "font family:" background color: #ffffff; ">( Face recognition, automatic driving, intelligent security,License plate recognition, certificate identification) < / span ></ span><span style="font-family:"background-color:#FFFFFF;"> Therefore, the computational vision industry based on artificial intelligence is bound to give birth to a large number of work and entrepreneurial opportunities. How to quickly enter the CV field with both theoretical basis and practical ability has become the concern of most learners, and this course is designed because of this original intention< br /> </span> </p> <p style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> <br /> </p> <p style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> <span style="font-size:16px; color:#337FE5;">< Strong > [instructor introduction] < / strong ></span> </p> <p style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> <span style="font-size:16px; color:#337FE5;">< strong>CH<strong><span style="font-family:"color:#222226; font-size:16px; background-color:#FFFFFF; font-weight:700;"> Arlie teacher < / span > < / strong > < / strong ></span> </p> 1. Artificial intelligence algorithm scientist < br / > 2. Shenzhen overseas high-level talent recognition (peacock talent) < br / > 3. Postdoctoral Fellow, National Supercomputing Center, San Diego, USA < br / > 4. University of California San Diego full award doctor < br / > 5. Participated in 392mw funded by NSF and CEC Ivanpah and other smart grid projects < br / > 6. 21 international journal articles (17 included in SCI), with a total citation of nearly 1000 < br / > 7. 11 invention patents of the first author < br / > <p> <br /> </p> <p class="ql-long-24357476" style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> <span style="font-family:"color:#337FE5;">< span><span style="font-size:16px;">< Strong > [reason for recommending you to study this course: < / strong > < / span > < span style = "color: #e53333; font-size:16px;">< Strong > complete knowledge system + rich learning materials] < / strong ></span></span></span> </p> <p class="ql-long-24357476" style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> <span class="ql-author-24357476" style="font-family:""></span> </p> <p class="MsoNormal" style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> 1. This course consists of 9 chapters and is a coursesystemThe introductory computer vision course will continue to be updated in the future. </p> <p class="MsoNormal" style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> <span>2 < / span >, < span > courses start from the theoretical knowledge of computer vision, combine theory with practice, and realize the hand-in-hand combat code (Hough transform and template matching, < / span > < span > alexnet OCR < / span > < span > Application < / span > < span >, VGg < / span > < span > transfer learning, multi label classification algorithm Engineering)</span> </p> <p class="MsoNormal" style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> <span>3 < / span >, < span > take you to understand the cutting-edge technology, < / span > < span > the advantages and disadvantages of various types of algorithms, master data enhancement, < / span > < span > batchnormalization, dropout < / span > < span >, migration learning and other optimization skills, and buildpracticalDeep learning application model</span> </p> <p class="MsoNormal" style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> <span>4 < / span >. After learning, you will have the project ability of in-depth learning and computational vision. For example, college students can independently complete the graduation design of machine vision, systematically explain the core knowledge points of machine vision in the process of job hunting, and initially reach the level of machine vision engineers in the field of human intelligence </p> <span style="color:#222226; font-family:PingFangSC-Regular, "font-size:14px; background-color:#FFFFFF;"></ span> <p style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> <br /> </p> <p class="ql-long-24357476" style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> <strong><span style="color:#337FE5; font-size:16px;">【 What level will I reach after learning?]</ span></strong> </p> <p class="ql-long-24357476"> <span>1. < span style = "font family:" > zero foundation introductory computing vision, learning, mastering and applying from classicsimage processingTo deeply learn the key knowledge of classification tasks</span></span> </p> <p class="ql-long-24357476"> <span>2. < span style = "font family:" > master optimization skills such as data enhancement, migration and learning, and buildpracticalDeep learning application model</span></span> </p> <p class="ql-long-24357476"> <span>3. < span style = "font family:" > after learning the course, you can apply multiple classical algorithms and deep learning algorithms independently</span></span> </p> <p class="ql-long-24357476"> <span>4. < span style = "font family:" "> aiming at < / span > < span style =" font family: "" > college graduation design, interview and job search, < / span > < span style = "font family:" "> programming with your hands, you can complete the courses step by step and gain the experience of practical projects even if you don't have much background knowledge of computational vision</span></span> </p> <p class="ql-long-24357476"> <br /> </p> <p class="ql-long-24357476"> <span style="color:#337FE5;">< b><span style="background-color:#FFFFFF; color:#337FE5;">< span style="font-size:16px; color:#337FE5;">【 Crowd oriented] < / span > < / span ></b></span> </p> <p class="ql-long-24357476"> <span>1. Interested in AI, want tosystemStudents studying computer vision</span> </p> <p class="ql-long-24357476"> <span>2、<span style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> College students who need graduation design</span></span> </p> <p class="ql-long-24357476"> <span>3、<span style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> A graduate student who does image analysis or related data analysis</span></span> </p> <p class="ql-long-24357476"> <span>4、<span style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> Prepare to interview candidates for computing vision and deep learning positions</span></span> </p> <p class="ql-long-24357476"> <span>5、<span style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> I hope to introduce computational vision into the project < / span > < span style = "font family:" color: #222226; font-size:14px; background-color:#FFFFFF;">/</ span><span style="font-family:"color:#222226; font-size:14px; background-color:#FFFFFF;"> Developers of deep learning technology</span></span> </p> <p class="ql-long-24357476"> <br /> </p> <p class="ql-long-24357476"> <b><span style="font-family:"font-size:16px; background-color:#FFFFFF; color:#337FE5;">< span style="font-size:16px; color:#337FE5;">【 Course knowledge system diagram < / span > < span style = "font size: 16px; color:#337FE5;">】</ span></span></b> </p> <p class="ql-long-24357476"> <span><b><img src=" https://img-bss.csdnimg.cn/202007140746422581.png " alt="" /></b></span> </p> <p class="ql-long-24357476"> <span><b><br /> </b></span> </p> <p class="ql-long-24357476"> <span style="font-size:16px; color:#337FE5;">< b> [practical project]</b></span> </p> <p class="ql-long-24357476"> <b><img src=" https://img-bss.csdnimg.cn/202007150352244062.png " alt="" /><img src=" https://img-bss.csdnimg.cn/202007150517376530.png " alt="" /></b> </p> <p class="ql-long-24357476"> <br /> </p>
emoticon
Insert expression
Relevant recommendations More similar content
©️ 2020 CSDN Skin theme: swimming - white Designer: Bai Songlin Return to home page
Paid inelement
Payment with balance
Click retrieve
Code scanning payment
Wallet balance 0

Deduction Description:

1. The balance is the virtual currency of wallet recharge, and the payment amount is deducted according to the ratio of 1:1.
2. The balance cannot be purchased and downloaded directly. You can buy VIP, c-coin package, paid column and courses.

Balance recharge
mbapedia4.com