python例程:智能停车场车牌识别计费系统的程序
目录
- 《智能停车场车牌识别计费系统》程序使用说明
- 主要代码演示
- 源码下载路径
《智能停车场车牌识别计费系统》程序使用说明
在PyCharm中运行《智能停车场车牌识别计费系统》即可进入如图1所示的系统主界面。
图1 系统主界面
说明:在运行程序前,先将当前的计算机连接互联网,并且需要先申请百度AI开放平台的图片识别需要的Key,并且复制该Key到项目根目录下的file子目录的key.txt文件中替换相应的内容即可。替换时需要注意不要把原来的单引号删除。
具体的操作步骤如下:
(1)识别车牌,并实现车辆入场和出场。当有车辆的车头或车尾对准摄像头后,管理员单击“识别”按钮,系统将识别该车牌,并且根据车牌判断入场或出场,显示不同信息。车辆入场时效果如图2所示,车辆驶出时效果如图3所示。
图2 车辆入场
图3 车辆出场
(2)收入统计。单击“收入统计”按钮,系统会根据车辆进出记录汇总出一个的收入信息,并且通过柱型图显示出来,效果如图4所示。
图4 收入统计
(3)满预警。系统会根据以往的数据自动判断一周中的哪一天会出现车位紧张的情况,从而在前一天给出预警提示,方便管理员提前做好调度,效果如图5所示。
图5 满预警提示
主要代码演示
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import cv2
import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plt
import pygameimport time
import osimport ocrutil
import btn
import timeutil# 定义颜色
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
BLUE = (0, 120, 215)
GRAY = (96,96,96)
RED = (220,20,60)
YELLOW = (255,255,0)
DARKBLUE = (73, 119, 142)
BG = DARKBLUE # 指定背景颜色
#信息内容
txt1=''
txt2=''
txt3=''
# 窗体大小
size = 1000, 484
# 设置帧率(屏幕每秒刷新的次数)
FPS = 60
# 一共有多少车位
Total =100
# 月收入统计分析界面开关
income_switch=False# 获取文件的路径
cdir = os.getcwd()
# 文件路径
path=cdir+'/datafile/'
# 读取路径
if not os.path.exists(path):# 根据路径建立文件夹os.makedirs(path)# 车牌号 日期 时间 价格 状态carnfile = pd.DataFrame(columns=['carnumber', 'date', 'price', 'state'])# 生成xlsx文件carnfile.to_excel(path+'停车场车辆表' + '.xlsx', sheet_name='data')carnfile.to_excel(path+'停车场信息表' + '.xlsx', sheet_name='data')# 读取文件内容
pi_table = pd.read_excel(path+'停车场车辆表.xlsx', sheet_name='data')
pi_info_table = pd.read_excel(path+'停车场信息表.xlsx', sheet_name='data')
# 停车场车辆
cars = pi_table[['carnumber', 'date', 'state']].values
# 已进入车辆数量
carn =len(cars)# pygame初始化
pygame.init()
# 设置窗体名称
pygame.display.set_caption('智能停车场车牌识别计费系统')
# 图标
ic_launcher = pygame.image.load('file/ic_launcher.png')
# 设置图标
pygame.display.set_icon(ic_launcher)
# 设置窗体大小
screen=pygame.display.set_mode(size)
# 设置背景颜色
screen.fill(BG)try:cam = cv2.VideoCapture(0)
except:print('请连接摄像头')# 背景文图案
def text0(screen):# 底色pygame.draw.rect(screen, BG, (650, 2, 350, 640))# 绘制横线pygame.draw.aaline(screen, GREEN, (662, 50), (980, 50), 1)# 绘制信息矩形框pygame.draw.rect(screen, GREEN, (650, 350, 342,85),1)# 使用系统字体xtfont = pygame.font.SysFont('SimHei', 15)# 重新开始按钮textstart = xtfont.render('信息', True, GREEN)# 获取文字图像位置text_rect = textstart.get_rect()# 设置文字图像中心点text_rect.centerx = 675text_rect.centery = 365# 绘制内容screen.blit(textstart, text_rect)cars = pi_table[['carnumber', 'date', 'state']].valuesif len(cars)>0:longcar=cars[0][0]cartime =cars[0][1]# 使用系统字体xtfont = pygame.font.SysFont('SimHei', 15)# 转换当前时间 2018-12-11 16:18localtime = time.strftime('%Y-%m-%d %H:%M', time.localtime())htime = timeutil.DtCalc(cartime, localtime)# 重新开始按钮textscar = xtfont.render('停车时间最长车辆:'+str(longcar), True, RED)texttime = xtfont.render("已停车:" + str(htime) + '小时', True, RED)# 获取文字图像位置text_rect1 = textscar.get_rect()text_rect2 = texttime.get_rect()# 设置文字图像中心点text_rect1.centerx = 820text_rect1.centery = 320text_rect2.centerx = 820text_rect2.centery = 335# 绘制内容screen.blit(textscar, text_rect1)screen.blit(texttime, text_rect2)pass# 车位文字
def text1(screen):# 剩余车位k =Total - carnif k<10:# 剩余车位sk='0'+str(k)else:sk =str(k)# 使用系统字体xtfont = pygame.font.SysFont('SimHei', 20)# 重新开始按钮textstart = xtfont.render('共有车位:'+str(Total)+' 剩余车位:'+sk, True,WHITE)# 获取文字图像位置text_rect = textstart.get_rect()# 设置文字图像中心点text_rect.centerx =820text_rect.centery =30# 绘制内容screen.blit(textstart, text_rect)# 停车场信息表头
def text2(screen):# 使用系统字体xtfont = pygame.font.SysFont('SimHei', 15)# 重新开始按钮textstart = xtfont.render(' 车号 时间 ', True,WHITE)# 获取文字图像位置text_rect = textstart.get_rect()# 设置文字图像中心点text_rect.centerx =820text_rect.centery =70# 绘制内容screen.blit(textstart, text_rect)pass# 停车场车辆信息
def text3(screen):# 使用系统字体xtfont = pygame.font.SysFont('SimHei', 12)# 获取文档表信息cars = pi_table[['carnumber', 'date', 'state']].values# 页面就绘制10辆车信息if len(cars) > 10:cars = pd.read_excel(path + '停车场车辆表.xlsx', skiprows=len(cars) - 10, sheet_name='data').values# 动态绘制y点变量n=0# 循环文档信息for car in cars:n+=1# 车辆车号 车辆进入时间textstart = xtfont.render( str(car[0])+' '+str(car[1]), True, WHITE)# 获取文字图像位置text_rect = textstart.get_rect()# 设置文字图像中心点text_rect.centerx = 820text_rect.centery = 70+20*n# 绘制内容screen.blit(textstart, text_rect)pass# 历史信息 满预警信息
def text4(screen,txt1,txt2,txt3):# 使用系统字体xtfont = pygame.font.SysFont('SimHei', 15)texttxt1 = xtfont.render(txt1, True, GREEN)# 获取文字图像位置text_rect = texttxt1.get_rect()# 设置文字图像中心点text_rect.centerx = 820text_rect.centery = 355+20# 绘制内容screen.blit(texttxt1, text_rect)texttxt2 = xtfont.render(txt2, True, GREEN)# 获取文字图像位置text_rect = texttxt2.get_rect()# 设置文字图像中心点text_rect.centerx = 820text_rect.centery = 355+40# 绘制内容screen.blit(texttxt2, text_rect)texttxt3 = xtfont.render(txt3, True, GREEN)# 获取文字图像位置text_rect = texttxt3.get_rect()# 设置文字图像中心点text_rect.centerx = 820text_rect.centery = 355+60# 绘制内容screen.blit(texttxt3, text_rect)# 满预警kcar = pi_info_table[pi_info_table['state'] == 2]kcars = kcar['date'].values# 周标记 0代表周一week_number=0for k in kcars:week_number=timeutil.get_week_numbeer(k)# 转换当前时间 2018-12-11 16:18localtime = time.strftime('%Y-%m-%d %H:%M', time.localtime())# 根据时间返回周标记 0代表周一week_localtime=timeutil.get_week_numbeer(localtime)if week_number ==0:if week_localtime==6 :text6(screen,'根据数据分析,明天可能出现车位紧张的情况,请提前做好调度!')elif week_localtime==0:text6(screen,'根据数据分析,今天可能出现车位紧张的情况,请做好调度!')else:if week_localtime+1==week_number:text6(screen, '根据数据分析,明天可能出现车位紧张的情况,请提前做好调度!')elif week_localtime==week_number:text6(screen, '根据数据分析,今天可能出现车位紧张的情况,请做好调度!')pass# 收入统计
def text5(screen):# 计算price列 和sum_price = pi_info_table['price'].sum()# print(str(sum_price) + '元')# 使用系统字体xtfont = pygame.font.SysFont('SimHei', 20)# 重新开始按钮textstart = xtfont.render('共计收入:' + str(int(sum_price)) + '元', True, WHITE)# 获取文字图像位置text_rect = textstart.get_rect()# 设置文字图像中心点text_rect.centerx = 1200text_rect.centery = 30# 绘制内容screen.blit(textstart, text_rect)# 加载图像image = pygame.image.load('file/income.png')# 设置图片大小image = pygame.transform.scale(image, (390, 430))# 绘制月收入图表screen.blit(image, (1000,50))# 显示满预警提示内容
def text6(screen,week_info):pygame.draw.rect(screen, YELLOW, ((2, 2), (640, 40)))xtfont = pygame.font.SysFont('SimHei', 22)textweek_day = xtfont.render(week_info, True, RED)# 获取文字图像位置text_rectw = textweek_day.get_rect()# 设置文字图像中心点text_rectw.centerx = 322text_rectw.centery = 20# 绘制内容screen.blit(textweek_day, text_rectw)# 游戏循环帧率设置
clock = pygame.time.Clock()
# 主线程
Running =True
while Running:# 从摄像头读取图片sucess, img = cam.read()# 保存图片,并退出。cv2.imwrite('file/test.jpg', img)# 加载图像image = pygame.image.load('file/test.jpg')# 设置图片大小image = pygame.transform.scale(image, (640, 480))# 绘制视频画面screen.blit(image, (2,2))# 背景文字图案text0(screen)# 停车位信息text1(screen)# 停车场信息表头text2(screen)# 停车场车辆信息text3(screen)# 提示信息text4(screen, txt1, txt2, txt3)# 创建识别按钮button_go = btn.Button(screen, (640, 480), 150, 60, BLUE, WHITE, "识别", 25)# 绘制创建的按钮button_go.draw_button()# 创建分析按钮button_go1 = btn.Button(screen, (990, 480), 100, 40, RED, WHITE, "收入统计", 18)# 绘制创建的按钮button_go1.draw_button()# 判断是否开启了收入统计按钮if income_switch:# 开启时候绘制页面text5(screen)passelse:passfor event in pygame.event.get():# 关闭页面游戏退出if event.type == pygame.QUIT:# 退出pygame.quit()# 关闭摄像头cam.release()exit()#判断点击elif event.type == pygame.MOUSEBUTTONDOWN:# 输出鼠标点击位置print(str(event.pos[0])+':'+str(event.pos[1]))# 判断是否点击了收入统计按钮位置# 收入统计按钮if 890 <= event.pos[0] and event.pos[0] <= 990 \and 440 <= event.pos[1] and event.pos[1] <= 480:print('分析统计按钮')if income_switch:income_switch = False# 设置窗体大小size = 1000, 484screen = pygame.display.set_mode(size)screen.fill(BG)else:income_switch = True# 设置窗体大小size = 1400, 484screen = pygame.display.set_mode(size)screen.fill(BG)attr = ['1月', '2月', '3月', '4月', '5月','6月', '7月', '8月', '9月', '10月', '11月', '12月']v1 = []# 循环添加数据for i in range(1, 13):k = iif i < 10:k = '0' + str(k)#筛选每月数据kk = pi_info_table[pi_info_table['date'].str.contains('2019-' + str(k))]# 计算价格和kk = kk['price'].sum()v1.append(kk)# 设置字体可以显示中文plt.rcParams['font.sans-serif'] = ['SimHei']# 设置生成柱状图图片大小plt.figure(figsize=(3.9, 4.3))# 设置柱状图属性 attr为x轴内容 v1为x轴内容相对的数据plt.bar(attr, v1, 0.5, color="green")# 设置数字标签for a, b in zip(attr, v1):plt.text(a, b, '%.0f' % b, ha='center', va='bottom', fontsize=7)# 设置柱状图标题plt.title("每月收入统计")# 设置y轴范围plt.ylim((0, max(v1) + 50))# 生成图片plt.savefig('file/income.png')pass# 判断是否点击了识别按钮位置#识别按钮if 492<=event.pos[0] and event.pos[0]<=642 and 422<=event.pos[1] and event.pos[1]<=482:print('点击识别')try:# 获取车牌carnumber=ocrutil.getcn()# 转换当前时间 2018-12-11 16:18localtime = time.strftime('%Y-%m-%d %H:%M', time.localtime())# 获取车牌号列数据carsk = pi_table['carnumber'].values# 判断当前识别得车是否为停车场车辆if carnumber in carsk:txt1='车牌号: '+carnumber# 时间差y=0# 获取行数用kcar=0# 获取文档内容cars = pi_table[['carnumber', 'date', 'state']].values# 循环数据for car in cars:# 判断当前车辆根据当前车辆获取时间if carnumber ==car[0]:# 计算时间差 0,1,2...y = timeutil.DtCalc(car[1], localtime)break#行数+1kcar = kcar + 1#判断停车时间 如果时间if y==0:y=1txt2='停车费:'+str(3*y)+'元'txt3='出停车场时间:'+localtime# 删除停车场车辆表信息pi_table=pi_table.drop([kcar],axis = 0)# 更新停车场信息pi_info_table=pi_info_table.append({'carnumber': carnumber,'date': localtime,'price':3*y,'state': 1}, ignore_index=True)# #保存信息更新xlsx文件DataFrame(pi_table).to_excel(path + '停车场车辆表' + '.xlsx',sheet_name='data', index=False, header=True)DataFrame(pi_info_table).to_excel(path + '停车场信息表' + '.xlsx',sheet_name='data', index=False, header=True)# 停车场车辆carn -= 1else:if carn <=Total:# 添加信息到文档 ['carnumber', 'date', 'price', 'state']pi_table=pi_table.append({'carnumber': carnumber,'date': localtime ,'state': 0}, ignore_index=True)# 更新xlsx文件DataFrame(pi_table).to_excel(path + '停车场车辆表' + '.xlsx',sheet_name='data', index=False, header=True)if carn<Total:# state等于0得时候为 停车场有车位进入停车场pi_info_table = pi_info_table.append({'carnumber': carnumber,'date': localtime,'state': 0}, ignore_index=True)# 车辆数量+1carn += 1else:# state等于2得时候为 停车场没有车位的时候pi_info_table = pi_info_table.append({'carnumber': carnumber,'date': localtime,'state': 2}, ignore_index=True)DataFrame(pi_info_table).to_excel(path + '停车场信息表' + '.xlsx',sheet_name='data', index=False,header=True)# 有停车位提示信息txt1 = '车牌号: ' + carnumbertxt2 = '有空余车辆,可以进入停车场'txt3 = '进停车场时间:'+localtimeelse:# 停车位满了得时候提示信息txt1 = '车牌号: ' + carnumbertxt2 = '没有空余车位,不可以进入停车场'txt3 = '时间:' + localtimeexcept Exception as e:print("错误原因:",e)continuepass# 跟新界面pygame.display.flip()# 控制游戏最大帧率为 60clock.tick(FPS)
#关闭摄像头
cam.release()
源码下载路径
python例程-智能停车场车牌识别计费系统的程序使用说明.zip
python例程:智能停车场车牌识别计费系统的程序相关推荐
- Python实现智能停车场车牌识别计费系统
前段时间练习过的一个小项目,今天再看看,记录一下~ 项目结构 说明: datefile文件夹:保存车辆信息表的xlsx文件 file文件夹:保存图片文件夹.ic_launcher.jpg是窗体的右上角 ...
- 智能停车场车牌识别计费系统
具体的操作步骤如下: (1)识别车牌,并实现车辆入场和出场.当有车辆的车头或车尾对准摄像头后,管理员单击"识别"按钮,系统将识别该车牌,并且根据车牌判断入场或出场,显示不同信息.车 ...
- 智能停车场车牌识别系统(一)
前段时间练习过的一个小项目,今天再看看,记录一下~ 开发工具准备: 开发工具:PyCharm Python内置模块:os.time.datetime 第三方模块:pygame.opencv-pytho ...
- 智能停车场车牌识别系统(二)
在上一篇文章实现车牌识别功能的基础上,加入了实现收入统计功能和满预警功能 看这篇文章之前请先完成 智能停车场车牌识别系统(一) 的阅读 实现收入统计功能: 收入统计就是对停车场每个月的收入进行统计,然 ...
- QT+Python停车场车牌识别计费管理系统
程序示例精选 Python停车场车牌识别计费管理系统 如需安装运行环境或远程调试,见文章底部微信名片! 前言 QT+Python是非常经典的窗体编程组合,功能完善,可视化界面美观易维护,这篇博客针对停 ...
- 停车场车牌识别收费系统厂家
车牌识别,车牌识别系统,智能道闸,广告道闸,平移门,升降立柱,人脸识别,无人值守收费系统,停车场设备.设计报价上门安装请联系我的用户名 据中安网数据显示,2019年我国安防产品总产值为2500亿元,结 ...
- python车牌识别系统抬杆_【小区停车场车牌识别系统 车辆进门道闸自动抬杆】 - 太平洋安防网...
[参数说明] 品牌:交安通 号牌检出率::白天≥99.9%:夜间≥99.7% 号牌识别率::白天≥98%:夜间≥97% 拍摄范围::3-10米 [详细描述] 小区停车场车牌识别系统 车辆进门道闸自动抬 ...
- pkr车牌识别系统服务器,JAT-PKR-交安通PKR停车场车牌识别管理系统
交安通PKR停车场车牌识别管理系统特点: 识别系统对环境的依赖性降低至zui低程度,可实现全天候正常工作,且识别率保持较高水平. 可识别的zui小号牌宽度为70个像素 适应复杂的气候及光照条件,如阴天 ...
- 车牌识别停车系统无法链接服务器,停车场车牌识别系统识别不了的处理方法有哪些?...
跟着科技的不断进步,越来越多的高科技产品运用于咱们的生产.生活中,给大家的生活带来了便利,下面咱们一起来了解一下停车场车牌识别不了怎么办的相关处理方法吧. 一.对感光部件对外部环境的处理. 环境是影响 ...
最新文章
- PHP Session中保存Object
- CEO换人、IPO延期,比特大陆艰难转型路漫漫
- 深圳美景品牌策划机构:美景、BOBDOG传媒合作论坛广州举行
- Precog:大数据分析即服务
- android so readelf.exe,android ndk中的工具使用
- 数据脱敏和加密_Apache ShardingSphere数据脱敏全解决方案详解
- 信安教程第二版-第15章网络安全主动防御技术与应用
- svn提交报错Previous operation has not finished; run 'cleanup' if it was interrupted
- 《CLR Via C# 第3版》笔记之(八) - 类型的转换构造器和方法
- 基于python下django框架 实现校园二手书籍交易系统详细设计
- 【爬虫】【原创】08 使用简单正则表达式爬取下厨房(早餐,午餐,晚餐)
- 视频融合技术平台解决方案
- ROC:Receiver operating characteristic Curve接受者操作特征的理解
- 修复损坏文件,给电脑保驾续航
- OpenCore Gen-X :一键制作黑苹果OpenCore EFI文件
- zblog php 火车头,ZBLOG PHP版火车头采集器免登录文章发布模块使用记录
- java把字符串转换为数组
- 微软计算机电源怎么接,IT之家学院:解决微软Surface连接电源充电未满却显示“未在充电”的小技巧...
- mathtype嵌入word后仍为灰色怎么解决?
- 《数据处理与知识发现》章节测验复习
热门文章
- Java程序逻辑控制
- android 去广告教程,安卓逆向系列教程 4.6 去广告
- 50个Bootstrap扩展插件
- php html5 游戏,分享一款HTML5小游戏绵羊快跑
- 高性能计算(High Performance Computing)
- 银联接口对接demo测试
- 工业控制计算机硬件基础知识,第五章 工业控制计算机及其接口技术知识 机电一体化课件.ppt...
- 解惑 功能需求和非功能性需求
- Java基础知识(重点)总结(Java学习方法、系统学习路线)
- canvas绘制字体时遇到Bookshelf Symbol 7字体bug