车牌识别算法 基于yolov5的车牌检测+crnn中文车牌识别 支持12种中文车牌识别

2023-05-16

yolov5 车牌识别算法,支持12种中文车牌类型 基于yolov5的车牌检测 车牌矫正以及 基于CRNN的车牌识别

1.单行蓝牌 2.单行黄牌 3.新能源车牌 4.白色警用车牌 5 教练车牌 6 武警车牌 7 双层黄牌 8 双层武警 9 使馆车牌 10 港澳牌车 11 双层农用车牌 12 民航车牌
效果如下:请添加图片描述

基于yolov5车牌检测

车牌检测+关键点定位

1.第一步是目标检测,目标检测大家都很熟悉,常见的yolo系列,这里的话我用的是我修改后的yolov5系列),用yolov5训练的车牌检测效果如下:
在这里插入图片描述

如果对上面这样图片进行识别的话,那么干扰信息很多,会造成误识别,这里就是为什么要进行关键点识别,假设我们得到车牌的四个角点坐标:
通过透视变换,透视变换即可得到下图:
在这里插入图片描述
这样的图片进行识别的话就会非常容易了
所以在检测的同时,我们需要进行关键点定位
透视变换代码:

def four_point_transform(image, pts):
    # obtain a consistent order of the points and unpack them
    # individually
    rect = order_points(pts)
    (tl, tr, br, bl) = rect
 
    # compute the width of the new image, which will be the
    # maximum distance between bottom-right and bottom-left
    # x-coordiates or the top-right and top-left x-coordinates
    widthA = np.sqrt(((br[0] - bl[0]) ** 2) + ((br[1] - bl[1]) ** 2))
    widthB = np.sqrt(((tr[0] - tl[0]) ** 2) + ((tr[1] - tl[1]) ** 2))
    maxWidth = max(int(widthA), int(widthB))
 
    # compute the height of the new image, which will be the
    # maximum distance between the top-right and bottom-right
    # y-coordinates or the top-left and bottom-left y-coordinates
    heightA = np.sqrt(((tr[0] - br[0]) ** 2) + ((tr[1] - br[1]) ** 2))
    heightB = np.sqrt(((tl[0] - bl[0]) ** 2) + ((tl[1] - bl[1]) ** 2))
    maxHeight = max(int(heightA), int(heightB))
 
    # now that we have the dimensions of the new image, construct
    # the set of destination points to obtain a "birds eye view",
    # (i.e. top-down view) of the image, again specifying points
    # in the top-left, top-right, bottom-right, and bottom-left
    # order
    dst = np.array([
        [0, 0],
        [maxWidth - 1, 0],
        [maxWidth - 1, maxHeight - 1],
        [0, maxHeight - 1]], dtype = "float32")
 
    # compute the perspective transform matrix and then apply it
    M = cv2.getPerspectiveTransform(rect, dst)
    warped = cv2.warpPerspective(image, M, (maxWidth, maxHeight))
 
    # return the warped image
    return warped

2.这里关键点定位我们利用和人脸识别类似的方法进行,人脸是5个点,而车牌我们仅仅需要四个点就可以了。

车牌检测训练数据集可以主要利用了CRPD 和CCPD数据集

车牌识别

拿到车牌区域的图片后就可以利用crnn进行车牌识别了
整理了一些数据,包括12种车牌的训练数据集,以及训练步骤
车牌识别代码:my_demo_new.py

from plateNet import myNet_ocr
import torch
import torch.nn as nn
import cv2
import numpy as np
import os
import time
import argparse
def cv_imread(path):   #读取中文路径的图片
    img=cv2.imdecode(np.fromfile(path,dtype=np.uint8),-1)
    return img

def allFilePath(rootPath,allFIleList):
    fileList = os.listdir(rootPath)
    for temp in fileList:
        if os.path.isfile(os.path.join(rootPath,temp)):
            allFIleList.append(os.path.join(rootPath,temp))
        else:
            allFilePath(os.path.join(rootPath,temp),allFIleList)

# plateName="#京沪津渝冀晋蒙辽吉黑苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云藏陕甘青宁新学警港澳挂使领民深危险品0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
plateName=r"#京沪津渝冀晋蒙辽吉黑苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云藏陕甘青宁新学警港澳挂使领民航深0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
mean_value,std_value=(0.588,0.193)
def decodePlate(preds):
    pre=0
    newPreds=[]
    for i in range(len(preds)):
        if preds[i]!=0 and preds[i]!=pre:
            newPreds.append(preds[i])
        pre=preds[i]
    return newPreds

def image_processing(img,device):
    img = cv2.resize(img, (168,48))
    img = np.reshape(img, (48, 168, 3))

    # normalize
    img = img.astype(np.float32)
    img = (img / 255. - mean_value) / std_value
    img = img.transpose([2, 0, 1])
    img = torch.from_numpy(img)

    img = img.to(device)
    img = img.view(1, *img.size())
    return img

def get_plate_result(img,device,model):
    # img = cv2.imread(image_path)
    input = image_processing(img,device)
    preds = model(input)
    # print(preds)
    preds=preds.view(-1).detach().cpu().numpy()
    newPreds=decodePlate(preds)
    plate=""
    for i in newPreds:
        plate+=plateName[i]
    return plate

def init_model(device,model_path):
    check_point = torch.load(model_path,map_location=device)
    model_state=check_point['state_dict']
    cfg = check_point['cfg']
    model = myNet_ocr(num_classes=78,export=True,cfg=cfg)        #export  True 用来推理
    model.load_state_dict(model_state)
    model.to(device)
    model.eval()
    return model
    
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--model_path', type=str, default='output/360CC/crnn/2022-09-26-21-30/checkpoints/checkpoint_11_acc_0.9657.pth', help='model.pt path(s)')  
    parser.add_argument('--image_path', type=str, default='images', help='source') 
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    # device =torch.device("cpu")
    opt = parser.parse_args()
    model = init_model(device,opt.model_path)
    if os.path.isfile(opt.image_path): 
        right=0
        begin = time.time()
        img = cv_imread(opt.image_path)
        if img.shape[-1]!=3:
            img = cv2.cvtColor(img,cv2.COLOR_BGRA2BGR)
        plate=get_plate_result(img, device,model)
        print(plate)
    else:
            file_list=[]
            allFilePath(opt.image_path,file_list)
            for pic_ in file_list:
                try:
                    pic_name = os.path.basename(pic_)
                    img = cv_imread(pic_)
                    if img.shape[-1]!=3:
                        img = cv2.cvtColor(img,cv2.COLOR_BGRA2BGR)
                    plate=get_plate_result(img,device,model)
                    print(plate,pic_name)
                except:
                    print("error")
                    
 

源码在这:

github车牌识别

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

车牌识别算法 基于yolov5的车牌检测+crnn中文车牌识别 支持12种中文车牌识别 的相关文章

随机推荐

  • ThreadLocal 适合用在哪些实际生产的场景中?

    在通常的业务开发中 xff0c ThreadLocal有两种典型的使用场景 场景1 xff0c ThreadLocal 用作保存每个线程独享的对象 xff0c 为每个线程都创建一个副本 xff0c 这样每个线程都可以修改自己所拥有的副本 而
  • SpringCloud 分布式事务组件之Seata

    目录 背景介绍什么是分布式事务什么叫做逆向补偿呢互联网最流行的分布式事务组件seata总结 背景 大家好 xff0c 今天给大家分享一个在2022年出去面试Java几乎必问的一个技术 xff0c 那就是seata 什么 xff1f xff1
  • 接口优化方案

    1 批量思想 xff1a 批量操作数据库 优化前 xff1a for循环单笔入库 for TransDetail detail transDetailList insert detail 优化后 xff1a batchInsert tran
  • springboot前端传一个对象后台怎么接受

    34 courseId 34 3 34 userId 34 34 1234456676 34 34 list 34 34 id 34 34 1 34 34 answer 34 34 B 34 34 id 34 34 1 34 34 answ
  • 前端传一个数组或者集合后台怎么接受

    34 id 34 34 1 34 34 answer 34 34 A 34 34 id 34 34 1 34 34 answer 34 34 A 34 这样的可以直接用一个 64 RequesBody List lt QuestionBac
  • Java8处理List的双层循环

    Java处理List的双层循环程序员经常遇到 xff0c 一般都是当两个List某个值满足某条件时候 xff0c 进行相应的处理 xff1b 1 list和map之间的相互转换 两个List对象当id相同的时候 注意是两个对象 而非两个集合
  • java如何抛出异常

    1 什么时候抛出异常 如果你觉得某些 问题 解决不了了 xff0c 那么你就可以抛出异常了 比如 xff0c 你在写一个service 其中在写到某段代码处 你发现可能会产生问题 xff0c 那么就请抛出异常吧 xff0c 相信我 xff0
  • 发送短信验证码过于频繁问题的解决

    1 对请求的接口做了一个限流的控制 2 利用到 AOP redis 定时器 3 在请求的congtroller层上加相应的注解就可以 具体的Demo工程如下 package com weigu xiaochuang project impo
  • spring的controller是单例还是多例

    我们经常说单例还是多例 那么究竟他们不同的根源在哪 或者说我们应该从哪一方面具体的去理解了 至于这个问题 今天做一个小的探讨 其实我们最终说的是 64 auowired注解的引入的service或mapper是不是单例还是多例的 这个是这个
  • 多线程-批量获取多条线程的执行结果

    当向线程池提交callable任务后 xff0c 我们可能需要一次性获取所有返回结果 xff0c 有三种处理方法 方法一 xff1a 自己维护返回结果 创建一个线程池 ExecutorService executorService 61 E
  • nautilus命令介绍

    nautilus 图形化桌面包括了一个叫做 Nautilus 的文件管理器 在GNOME中是Nautilus 鹦鹉螺 xff0c 而KDE中是Konqueror
  • 写个strcat函数

    include 34 stdio h 34 include lt string h gt void stracat char a char b char temp 128 char p 61 temp int alen 61 strlen
  • linux 下 tcp client的 demo

    include lt stdio h gt include lt stdlib h gt include lt string h gt include lt unistd h gt include lt sys socket h gt in
  • 解决MATLAB2020B关于找不到vs2019C++编译器问题

    在配置matlab 深度学习环境过程中 xff0c 出现找不到vs219C 43 43 编译器 问题 xff0c 尝试了各种办法 xff0c 还是失败 xff0c 经过摸索和结合他人经验 xff0c 最终成功 xff0c 予以总结 xff0
  • Ubuntu下使用w3m命令行模式浏览网页

    w3m是一个基于文本的网页浏览器 xff0c 支持多种操作系统 xff0c 在命令行终端可以很好的支持中文 即使在没有鼠标支持的情况下也可以检查网页的输出 我们一般用Ubuntu的X Windows来看图形界面的东西 xff0c 有没有想过
  • CC3D飞控说明书/使用手册

    CC3D飞控说明书 使用手册openpilot librepilot CC硬件配置 记得点赞哦 xff01 xff01 xff01
  • 串口服务器的原理及使用方法

    串口服务器是将来自TCP IP协议的数据包 xff0c 解析为串口数据流 xff1b 反之 xff0c 也可以将串口数据流打成TCP IP协议的数据包 xff0c 从而实现数据的网络传输 它能多个串口设备连接并能将串口数据流进行选择和处理
  • tcpdump命令

    tcpdump tcpdump命令介绍 tcpdump xff0c 用简单的语言概括就是dump the traffic on a network xff0c 是一个运行在linux平台可以根据使用者需求对网络上传输的数据包进行捕获的抓包工
  • 小程序登录后,接口调用失败返回401

    问题描述 xff1a 小程序登录后 xff0c 所有的内部接口不可调用 xff0c 全部授权失败 xff0c 接口返回401 xff1b 解决办法 xff1a 服务端清缓存就可以了 微信开发者工具中 xff0c 小程序多次登录 xff0c
  • 车牌识别算法 基于yolov5的车牌检测+crnn中文车牌识别 支持12种中文车牌识别

    yolov5 车牌识别算法 xff0c 支持12种中文车牌类型 基于yolov5的车牌检测 车牌矫正以及 基于CRNN的车牌识别 1 单行蓝牌 2 单行黄牌 3 新能源车牌 4 白色警用车牌 5 教练车牌 6 武警车牌 7 双层黄牌 8 双