python与tensoflow实现车牌识别

全部源码已上传至百度云,链接:https://pan.baidu.com/s/1PkTbcDap0W4BxcWnvoL78g
提取码:0hvf
实现效果如图所示:
在这里插入图片描述
识别模块为CNN文字识别,预处理为传统算法预处理,如下:
在这里插入图片描述
整套系统从数据采集,处理,包括定位,矫正,去噪,分割,识别。均有效实现。达到了90以上的识别准确率。
GUI界面代码如下:

import tkinter as tk
from tkinter.filedialog import *
from tkinter import ttk
import cv2
from PIL import Image, ImageTk
import time
from demo import demo


class Surface(ttk.Frame):
    pic_path = ""
    viewhigh = 300
    viewwide = 300
    update_time = 0
    thread = None
    thread_run = False
    camera = None


    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("zoomed")
        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)
        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)
        self.r_ctl = ttk.Label(frame_right1, text="")
        self.r_ctl.grid(column=0, row=3, sticky=tk.W)
        from_pic_ctl.pack(anchor="se", pady="5")


    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
            imgtk = ImageTk.PhotoImage(image=im)
        return imgtk

    def show_roi(self, text):
        if text :
            self.r_ctl.configure(text=str(text))
            self.update_time = time.time()
        elif self.update_time + 8 < time.time():
            self.r_ctl.configure(text="")

    def from_pic(self):
        self.thread_run = False
        self.pic_path = askopenfilename(title="选择追踪视频", filetypes=[("mp4文件", "*.mp4")])
        cap = cv2.VideoCapture(self.pic_path)
        print(self.pic_path)
        if self.pic_path:
            demo(cap)
            # text = Apply.cnn_recongnize_char(char_img_list, char_model_path)

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

if __name__ == '__main__':
    win=tk.Tk()
    surface = Surface(win)
    win.protocol('WM_DELETE_WINDOW', close_window)
    win.mainloop()


发布了257 篇原创文章 · 获赞 119 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/weixin_44517301/article/details/103411867
今日推荐