【Opencv实战】一文看懂车牌识别系统全部内容,未来市场前景看好(很赞)

本文介绍了车牌识别系统在智能交通中的重要性,并详细阐述了环境准备,包括Python、Pycharm等工具的使用,以及展示了系统的效果。通过代码片段揭示了系统的实现过程,提供了完整的素材和源码供读者参考学习。
摘要由CSDN通过智能技术生成

 前言

 车辆号牌是车辆唯一身份证,它的特殊性与重要性决定车牌识别系统成为城市智能交通管理系统

中不可或缺的重要组成部分。

未来,随着我国城市化进程发展的提速,交通压力将更加严峻,因此智能化交通管理将是今后交通

发展的大方向。今天小编就来带大家探索车牌识别系统!

一、环境准备

Python3、 Pycharm 、PIL、cv2 、tkinter 一些车牌图片的素材大家可以自由选择这里就不展示, 

等下会给大家随机找几组效果哈!

第三方库的安装:pip  install +模块名 如安装出现问题可以直接找我私信即可哈

二、效果展示

小程序界面:

效果展示:

 

 三、代码展示

主要有部分源码。这里仅展示部分。需要的找我拿完整的哈!

主程序界面:

import  tkinter as  tk
from tkinter.filedialog import  *
from tkinter import  ttk;
import predict
import  cv2
from PIL import  Image,ImageTk
import threading
import time

class Window(ttk.Frame):
    pic_path = ""
    viewHigh = 600
    viewWide = 600
    updataTime = 0
    thread = None
    threadRun = False
    camera = None
    colorTransform = {"green":("绿","#55ff55"),"yello":("黄","#ffff00"),"blue":{"蓝","#6666ff"}}

    def __init__(self,win):
        ttk.Frame.__init__(self,win)
        frame_left = ttk.Frame(self)
        frame_right1 = ttk.Frame(self)
        frame_right2= ttk.Frame(self)
        win.title("车牌识别")
        win.state("normal")
        self.pack(fill=tk.BOTH,expand=tk.YES,padx="5",pady="5")
        frame_left.pack(side=LEFT,expand=1,fill=BOTH)
        frame_right1.pack(side=TOP, expand=1, fill=tk.Y)
        frame_right2.pack(side=RIGHT, expand=0)
        ttk.Label(frame_left, text='原图:').pack(anchor="nw")
        ttk.Label(frame_right1, text='车牌位置:').grid(column=0, row=0, sticky=tk.W)

        from_pic_ctl = ttk.Button(frame_right2, text="打开图片", width=20, command=self.from_pic)

        self.image_ctl = ttk.Label(frame_left)
        self.image_ctl.pack(anchor="nw")

        self.roi_ctl = ttk.Label(frame_right1)
        self.roi_ctl.grid(column=0, row=1, sticky=tk.W)
        ttk.Label(frame_right1, text='识别结果:').grid(column=0, row=2, sticky=tk.W)
        self.r_ctl = ttk.Label(frame_right1, text="")
        self.r_ctl.grid(column=0, row=3, sticky=tk.W)
        self.color_ctl = ttk.Label(frame_right1, text="", width="20")
        self.color_ctl.grid(column=0, row=4, sticky=tk.W)
        from_pic_ctl.pack(anchor="se", pady="5")
        self.predictor = predict.CardPredictor()
        self.predictor.train_svm()

    def from_pic(self):
        self.threadRun = False
        self.pic_path = askopenfilename(title="选择识别图片",filetypes=[("jpg图片","*.jpg")])
        if self.pic_path:
            img_bgr = predict.imreadex(self.pic_path)
            self.imgtk = self.get_imgtk(img_bgr)
            self.image_ctl.configure(image=self.imgtk)
            r,roi,color = self.predictor.predict(img_bgr)
            self.show_roi(r,roi,color)

    def show_roi(self,r,roi,color):
        if r :
            roi = cv2.cvtColor(roi,cv2.COLOR_BGR2RGB)
            roi = Image.fromarray(roi)
            self.imgtk_roi = ImageTk.PhotoImage(image=roi)
            self.roi_ctl.configure(image=self.imgtk_roi, state='enable')
            self.r_ctl.configure(text=str(r))
            self.update_time = time.time()
            try:
                c = self.colorTransform[color]
                self.color_ctl.configure(text=c[0], background=c[1], state='enable')
            except:
                self.color_ctl.configure(state='disabled')
        elif   self.update_time + 8 < time.time():
                self.roi_ctl.configure(state='disabled')
                self.r_ctl.configure(text="")
                self.color_ctl.configure(state='disabled')

    def get_imgtk(self,img_bgr):
        img = cv2.cvtColor(img_bgr,cv2.COLOR_BGR2RGB)
        im = Image.fromarray(img)
        imgtk = ImageTk.PhotoImage(image=im)
        wide = imgtk.width()
        high = imgtk.height()
        if wide>self.viewWide or high > self.viewHigh:
            wide_factor = self.viewWide / wide
            high_factor = self.viewHigh / high
            factor = min(wide_factor,high_factor)
            wide = int(wide*factor)
            if wide <=0 : wide = 1
            high = int(high*factor)
            if high <= 0:high = 1
            im = im.resize((wide,high),Image.ANTIALIAS)
            imgtk = ImageTk.PhotoImage(image=im)
        return imgtk

def close_window():
    print("destroy")
    if window.threadRun :
        window.threadRun = False
        window.thread.join(2.0)
    win.destroy()


if __name__ == '__main__':
    win = tk.Tk()

    window = Window(win)
    win.protocol('WM_DELETE_WINDOW', close_window)
    win.mainloop()

模型训练:

import cv2
import numpy as np
from numpy.linalg import norm
import sys
import os
import json
from matplotlib import pyplot as plt

SZ = 20  # 训练图片长宽
MAX
  • 2
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值