智能停车场系统:基于 pyqt5,opencv,MySQL

这篇具有很好参考价值的文章主要介绍了智能停车场系统:基于 pyqt5,opencv,MySQL。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

这是一个相对复杂的项目,需要使用多个技术和模块来实现。以下是一个简单的示例代码,可以使用 Python 和 PyQt 实现一个简单的智能停车场管理系统。

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QLabel, QLineEdit, QPushButton, QMessageBox, QFileDialog
from PyQt5.QtGui import QPixmap
import mysql.connector
import cv2
import pytesseract
import datetime

class LoginWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("智能停车场管理系统-登录")
        self.setGeometry(100, 100, 600, 400)

        self.central_widget = QWidget(self)
        self.setCentralWidget(self.central_widget)

        self.username_label = QLabel("用户名:", self.central_widget)
        self.username_label.move(150, 100)
        self.username_input = QLineEdit(self.central_widget)
        self.username_input.move(220, 100)

        self.password_label = QLabel("密码:", self.central_widget)
        self.password_label.move(150, 150)
        self.password_input = QLineEdit(self.central_widget)
        self.password_input.move(220, 150)
        self.password_input.setEchoMode(QLineEdit.Password)

        self.login_button = QPushButton("登录", self.central_widget)
        self.login_button.move(250, 200)
        self.login_button.clicked.connect(self.login)

    def login(self):
        username = self.username_input.text()
        password = self.password_input.text()
        if username == "admin" and password == "123456":
            self.hide()
            self.main_window = MainWindow()
            self.main_window.show()
        else:
            QMessageBox.warning(self, "错误", "用户名或密码错误!")

class RegisterWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("智能停车场管理系统-注册")
        self.setGeometry(100, 100, 600, 400)

        self.central_widget = QWidget(self)
        self.setCentralWidget(self.central_widget)

        self.username_label = QLabel("用户名:", self.central_widget)
        self.username_label.move(150, 100)
        self.username_input = QLineEdit(self.central_widget)
        self.username_input.move(220, 100)

        self.password_label = QLabel("密码:", self.central_widget)
        self.password_label.move(150, 150)
        self.password_input = QLineEdit(self.central_widget)
        self.password_input.move(220, 150)
        self.password_input.setEchoMode(QLineEdit.Password)

        self.confirm_password_label = QLabel("确认密码:", self.central_widget)
        self.confirm_password_label.move(150, 200)
        self.confirm_password_input = QLineEdit(self.central_widget)
        self.confirm_password_input.move(220, 200)
        self.confirm_password_input.setEchoMode(QLineEdit.Password)

        self.register_button = QPushButton("注册", self.central_widget)
        self.register_button.move(250, 250)
        self.register_button.clicked.connect(self.register)

    def register(self):
        username = self.username_input.text()
        password = self.password_input.text()
        confirm_password = self.confirm_password_input.text()
        if password != confirm_password:
            QMessageBox.warning(self, "错误", "两次输入的密码不一致!")
        else:
            mydb = mysql.connector.connect(
                host="localhost",
                user="username",
                password="password",
                database="dbname"
            )
            mycursor = mydb.cursor()
            sql = "INSERT INTO users (username, password) VALUES (%s, %s)"
            val = (username, password)
            mycursor.execute(sql, val)
            mydb.commit()
            QMessageBox.information(self, "成功", "注册成功!")
            self.hide()

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("智能停车场管理系统-主页")
        self.setGeometry(100, 100, 800, 600)

        self.central_widget = QWidget(self)
        self.setCentralWidget(self.central_widget)

        self.camera_label = QLabel(self.central_widget)
        self.camera_label.setGeometry(50, 50, 640, 480)

        self.start_button = QPushButton("开始", self.central_widget)
        self.start_button.setGeometry(50, 550, 100, 30)
        self.start_button.clicked.connect(self.start_camera)

        self.stop_button = QPushButton("停止", self.central_widget)
        self.stop_button.setGeometry(200, 550, 100, 30)
        self.stop_button.clicked.connect(self.stop_camera)

        self.capture_button = QPushButton("拍照", self.central_widget)
        self.capture_button.setGeometry(350, 550, 100, 30)
        self.capture_button.clicked.connect(self.capture_image)

        self.plate_label = QLabel("车牌号码:", self.central_widget)
        self.plate_label.setGeometry(500, 550, 100, 30)
        self.plate_input = QLineEdit(self.central_widget)
        self.plate_input.setGeometry(600, 550, 100, 30)

        self.in_button = QPushButton("入库", self.central_widget)
        self.in_button.setGeometry(50, 500, 100, 30)
        self.in_button.clicked.connect(self.in_park)

        self.out_button = QPushButton("出库", self.central_widget)
        self.out_button.setGeometry(200, 500, 100, 30)
        self.out_button.clicked.connect(self.out_park)

        self.logout_button = QPushButton("注销", self.central_widget)
        self.logout_button.setGeometry(650, 20, 100, 30)
        self.logout_button.clicked.connect(self.logout)

        self.timer = None
        self.cap = None
        self.is_camera_running = False
        self.image_count = 0

    def start_camera(self):
        self.cap = cv2.VideoCapture(0)
        self.is_camera_running = True
        self.timer = self.central_widget.startTimer(20)

    def stop_camera(self):
        if self.cap:
            self.cap.release()
            self.is_camera_running = False
            self.timer = None
            self.camera_label.clear()

    def capture_image(self):
        if self.is_camera_running:
            ret, frame = self.cap.read()
            if ret:
                self.image_count += 1
                filename = "image_{}.jpg".format(self.image_count)
                cv2.imwrite(filename, frame)
                self.camera_label.setPixmap(QPixmap(filename))

                img = cv2.imread(filename)
                gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
                gray = cv2.medianBlur(gray, 3)
                gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
                plate = pytesseract.image_to_string(gray, config="--psm 7")
                self.plate_input.setText(plate.strip())

    def in_park(self):
        plate = self.plate_input.text()
        if plate:
            mydb = mysql.connector.connect(
                host="localhost",
                user="username",
                password="password",
                database="dbname"
            )
            mycursor = mydb.cursor()
            now = datetime.datetime.now()
            sql = "INSERT INTO park_record (plate, in_time) VALUES (%s, %s)"
            val = (plate, now.strftime("%Y-%m-%d %H:%M:%S"))
            mycursor.execute(sql, val)
            mydb.commit()
            QMessageBox.information(self, "成功", "车辆已入库!")
            self.plate_input.clear()

    def out_park(self):
        plate = self.plate_input.text()
        if plate:
            mydb = mysql.connector.connect(
                host="localhost",
                user="username",
                password="password",
                database="dbname"
            )
            mycursor = mydb.cursor()
            now = datetime.datetime.now()
            sql = "UPDATE park_record SET out_time = %s WHERE plate = %s AND out_time IS NULL"
            val = (now.strftime("%Y-%m-%d %H:%M:%S"), plate)
            mycursor.execute(sql, val)
            mydb.commit()
            if mycursor.rowcount > 0:
                QMessageBox.information(self, "成功", "车辆已出库!")
                self.plate_input.clear()
            else:
                QMessageBox.warning(self, "错误", "车牌号码不存在或已出库!")

    def logout(self):
        self.hide()
        self.login_window = LoginWindow()
        self.login_window.show()

    def timerEvent(self, event):
        if self.is_camera_running:
            ret, frame = self.cap.read()
            if ret:
                frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                h, w, ch = frame.shape
                bytesPerLine = ch * w
                qImg = QImage(frame.data, w, h, bytesPerLine, QImage.Format_RGB888)
                self.camera_label.setPixmap(QPixmap.fromImage(qImg))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    login_window = LoginWindow()
    login_window.show()
    sys.exit(app.exec_())

在上面的示例代码中,我们使用了 PyQt5 库来创建 GUI 界面,使用了 OpenCV 库来读取摄像头数据,并使用了 PyTesseract 库来识别车牌号码。同时,我们使用了 MySQL 数据库来存储车辆入库和出库记录。在程序运行时,首先会显示登录界面,用户可以输入用户名和密码来登录系统。如果登录成功,程序将转到主页界面,用户可以在主页界面中开启摄像头、拍照、识别车牌、入库或出库车辆,并可以注销用户退出系统。在程序中,我们使用了多个类来分别实现不同的功能,使代码更加清晰和易于维护。文章来源地址https://www.toymoban.com/news/detail-515901.html

到了这里,关于智能停车场系统:基于 pyqt5,opencv,MySQL的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • 基于单片机的智能停车场管理系统的设计与实现_kaic

    基于单片机的智能停车场管理系统的设计与实现_kaic

    摘 要 本设计基于RFID智能识别和高速的视频图像和存储比较相结合,通过计算机的图像处理和自动识别,对车辆进出停车场的收费、车牌识别和车位诱导等,以实现停车场全方位智能管理。 本设计是以AT89C51型单片机为主控芯片的智能停车场系统,主要是针对车辆诱导和车辆检

    2024年02月06日
    浏览(10)
  • 基于微信小程序的智能停车场系统-计算机毕业设计源码67860

    基于微信小程序的智能停车场系统-计算机毕业设计源码67860

    摘 要 科技进步的飞速发展引起人们日常生活的巨大变化,电子信息技术的飞速发展使得电子信息技术的各个领域的应用水平得到普及和应用。信息时代的到来已成为不可阻挡的时尚潮流,人类发展的历史正进入一个新时代。在现实运用中,应用软件的工作规则和开发步骤,

    2024年04月13日
    浏览(43)
  • 计算机Java项目|SSM基于微信小程序的智能停车场管理系统

    计算机Java项目|SSM基于微信小程序的智能停车场管理系统

      作者简介:Java领域优质创作者、CSDN博客专家 、CSDN内容合伙人、掘金特邀作者、阿里云博客专家、51CTO特邀作者、多年架构师设计经验、腾讯课堂常驻讲师 主要内容:Java项目、Python项目、前端项目、人工智能与大数据、简历模板、学习资料、面试题库、技术互助 收藏点赞

    2024年01月19日
    浏览(15)
  • 基于OpenCV构建停车场车位识别项目

    基于OpenCV构建停车场车位识别项目

    OpenCV是一个基于(开源)发行的跨平台计算机视觉库,能实现图像处理和计算机视觉方面的很多通用算法。车位识别的图像处理过程如图所示。 在python中设置完所有内容后, 最重要的依赖关系将是OpenCV库。通过pip将其添加到虚拟环境中,可以运行 pip install opencv-python 。 要检

    2024年02月05日
    浏览(11)
  • 基于 SpringBoot + Vue 的智能停车场项目。

    基于 SpringBoot + Vue 的智能停车场项目。

    一、开源项目简介 智能停车场管理平台!科学计费 多种计费方案灵活切换,商场、小区、停车场等场景均适用!无人值守 云端控制实现无岗亭模式下的车辆自主进出,降低人工成本! 使用MIT开源协议 系统管理:角色管理、接口管理、系统菜单、全局配置 账号管理:用户管

    2024年02月01日
    浏览(9)
  • 一种基于智能手机的地下停车场寻车系统

    原文来自于《Help You Locate the Car: a Smartphone-based Car-finding System in Underground Parking Lot》 这篇论文提出了一种基于智能手机的地下停车场寻车系统。该系统旨在帮助驾驶员在没有额外设备和地图支持的情况下找到他们的车辆。主要内容和贡献如下: 系统概述 : 目标 :解决在室内

    2024年01月17日
    浏览(8)
  • JAVA毕业设计119—基于Java+Springboot+vue的智能停车场管理系统(源代码+数据库+9000字论文)

    JAVA毕业设计119—基于Java+Springboot+vue的智能停车场管理系统(源代码+数据库+9000字论文)

    毕设所有选题: https://blog.csdn.net/2303_76227485/article/details/131104075 本项目前后端不分离 登录、控制台、停车场管理、车牌识别、车辆管理 角色管理、系统菜单、全局配置、停车记录、财务管理 控制台管理、系统日志、账号管理、用户管理、合作单位管理、密码修改、个人信息

    2024年02月03日
    浏览(10)
  • 【计算机毕业设计】智能停车场管理系统

    【计算机毕业设计】智能停车场管理系统

          摘 要 本论文主要论述了如何使用JAVA语言开发一个智能停车场管理系统,本系统将严格按照软件开发流程进行各个阶段的工作,采用B/S架构,面向对象编程思想进行项目开发。在引言中,作者将论述智能停车场管理的当前背景以及系统开发的目的,后续章节将严格按照

    2024年02月06日
    浏览(8)
  • 【功能超全】基于OpenCV车牌识别停车场管理系统软件开发【含python源码+PyqtUI界面+功能详解】-车牌识别python 深度学习实战项目

    【功能超全】基于OpenCV车牌识别停车场管理系统软件开发【含python源码+PyqtUI界面+功能详解】-车牌识别python 深度学习实战项目

    摘要: 车牌识别系统(Vehicle License Plate Recognition,VLPR) 是指能够检测到受监控路面的车辆并自动提取车辆牌照信息(含汉字字符、英文字母、阿拉伯数字及号牌颜色)进行处理的技术。车牌识别是现代智能交通系统中的重要组成部分之一,应用十分广泛。本文详细介绍了 车牌

    2024年02月09日
    浏览(13)
  • 【开源】基于JAVA的停车场收费系统

    【开源】基于JAVA的停车场收费系统

    基于JAVA+Vue+SpringBoot+MySQL的停车场收费系统,包含了车辆管理模块、停车场模块、停车记录模块、IC卡档案模块和IC卡挂失模块,还包含系统自带的用户管理、部门管理、角色管理、菜单管理、日志管理、数据字典管理、文件管理、图表展示等基础模块,停车场收费系统基于角

    2024年01月22日
    浏览(12)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包