900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > QT+Python停车场车牌识别计费管理系统

QT+Python停车场车牌识别计费管理系统

时间:2022-02-05 03:01:59

相关推荐

QT+Python停车场车牌识别计费管理系统

程序示例精选

Python停车场车牌识别计费管理系统

如需安装运行环境或远程调试,见文章底部微信名片!

前言

QT+Python是非常经典的窗体编程组合,功能完善,可视化界面美观易维护,这篇博客针对停车场车牌识别计费方面编写代码,代码整洁,规则,易读,对学习与使用Python有较好的帮助。

文章目录

一、所需工具软件

二、使用步骤

1. 引入库

2.导入车牌

3. 车牌识别

4. 运行结果

三、在线协助

一、所需工具软件

1. Python3.6以上

2. Pycharm代码编辑器

3. PyQT, OpenCV, Tensorflow, CSV, PIL库

二、使用步骤

1.引入库

代码如下(示例):

# coding:utf-8import csvimport cv2import numpy as npfrom PIL import Image, ImageTkfrom tensorflow import kerasfrom core import locate_and_correctfrom Unet import unet_predictfrom CNN import cnn_predictfrom PyQt5 import QtWidgets, QtCore, QtGuifrom PyQt5.QtGui import *from PyQt5.QtWidgets import *from PyQt5.QtCore import *import time

2.导入车牌

代码如下(示例):

def displayPlate(self):# 显示相片到label_2imgName, imgType = QFileDialog.getOpenFileName(self,"打开文件","./","files(*.*)")img = cv2.imread(imgName)#img = cv2.imread("test_img/aa.jpg")cv2.imwrite('temp.jpg', img)height, width, pixels = img.shapeframe = cv2.resize(img, (int(rwidth), int(rheight)))img2 = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # opencv读取的bgr格式图片转换成rgb格式_image = QtGui.QImage(img2[:], img2.shape[1], img2.shape[0], img2.shape[1] * 3, QtGui.QImage.Format_RGB888)jpg_out = QtGui.QPixmap(_image).scaled(rwidth, rheight) # 设置图片大小self.label.setPixmap(jpg_out) # 设置图片显示

该处使用的url网络请求的数据。

3.车牌识别:

代码如下(示例):

def carPlateRecogIn(self):print("carPlateRecog start")self.img_src_path="temp.jpg"img_src = cv2.imdecode(np.fromfile(self.img_src_path, dtype=np.uint8), -1) # 从中文路径读取时用h, w = img_src.shape[0], img_src.shape[1]print("aa")if h * w <= 240 * 80 and 2 <= w / h <= 5: # 满足该条件说明可能整个图片就是一张车牌,无需定位,直接识别即可lic = cv2.resize(img_src, dsize=(240, 80), interpolation=cv2.INTER_AREA)[:, :, :3] # 直接resize为(240,80)img_src_copy, Lic_img = img_src, [lic]else: # 否则就需通过unet对img_src原图预测,得到img_mask,实现车牌定位,然后进行识别img_src, img_mask = unet_predict(self.unet, self.img_src_path)img_src_copy, Lic_img = locate_and_correct(img_src, img_mask) # 利用core.py中的locate_and_correct函数进行车牌定位和矫正print("aa")Lic_pred = cnn_predict(n, Lic_img) # 利用cnn进行车牌的识别预测,Lic_pred中存的是元祖(车牌图片,识别结果)if Lic_pred:# 显示相片到label_2img = cv2.imread("temp.jpg")self.label.setPixmap(QPixmap(""))height, width, pixels = img.shapeframe = cv2.resize(img, (int(rwidth), int(rheight)))img2 = cv2.cvtColor(img_src_copy, cv2.COLOR_BGR2RGB) # opencv读取的bgr格式图片转换成rgb格式_image = QtGui.QImage(img2[:], img2.shape[1], img2.shape[0], img2.shape[1] * 3, QtGui.QImage.Format_RGB888)jpg_out = QtGui.QPixmap(_image).scaled(rwidth, rheight) # 设置图片大小self.label.setPixmap(jpg_out) # 设置图片显示for i, lic_pred in enumerate(Lic_pred):if i == 0:print("i: ", i)print("lic_pred[1]: ",lic_pred[1])self.textEdit.setPlainText("车牌编号:"+lic_pred[1])elif i == 1:print("i: ", i)self.textEdit.setPlainText("车牌编号:"+lic_pred[1])elif i == 2:print("i: ", i)self.textEdit.setPlainText("车牌编号:"+lic_pred[1])plateNumber=lic_pred[1]print("lic_pred[1]2: ", lic_pred[1])msg_box = QMessageBox(QMessageBox.Warning, '信息', '门已打开,请进入.....')msg_box.exec_()else: # Lic_pred为空说明未能识别print("无车牌发现")msg_box = QMessageBox(QMessageBox.Warning, '信息', '停车费已收取,请出门.....')msg_box.exec_()

4.运行结果如下:

三、在线协助:

如需安装运行环境或远程调试,见文章底部微信名片!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。