传统车牌识别

主要参考:https://blog.csdn.net/qq_40784418/article/details/105586644

其它介绍:

https://blog.csdn.net/great_yzl/article/details/120127962

https://blog.csdn.net/onepunch_k/article/details/115480904

cv2.matchTemplate

  • https://docs.opencv.org/3.4/d4/dc6/tutorial_py_template_matching.html

  • https://docs.opencv.org/3.4/df/dfb/group__imgproc__object.html#gga3a7850640f1fe1f58fe91a2d7583695dac5babb7dfda59544e3e31ea928f8cb16

  • https://blog.csdn.net/liyuanbhu/article/details/49837661

  • https://blog.csdn.net/m0_37579176/article/details/116950903

import cv2

old_img = cv2.imread('che1.png')
temp_img = old_img.copy()
# cv2.imshow('img',old_img)
# cv2.waitKey(1000)
img = old_img.copy()
img = cv2.GaussianBlur(img,(3,3),0)
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
sobel_x = cv2.Sobel(img_gray,cv2.CV_16S,1,0)
img_edge = cv2.convertScaleAbs(sobel_x)
_, img = cv2.threshold(img_edge,0,255,cv2.THRESH_OTSU)
kernelX = cv2.getStructuringElement(cv2.MORPH_RECT,(30,10))
img = cv2.morphologyEx(img,cv2.MORPH_CLOSE,kernelX,iterations=1)

kernelX = cv2.getStructuringElement(cv2.MORPH_RECT,(50,1))
kernelY = cv2.getStructuringElement(cv2.MORPH_RECT,(1,20))
img = cv2.dilate(img,kernelX)
img = cv2.erode(img,kernelX)
img = cv2.erode(img,kernelY)
img = cv2.dilate(img,kernelY)
img = cv2.medianBlur(img,21)

_, contours, _ = cv2.findContours(img,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
boxes = []
for contour in contours:
    rect = cv2.boundingRect(contour)
    x,y,w,h = rect
    if w*h < 100: continue
    if (w>h*2) and (w<h*4):
        boxes.append([x,y,w,h])
        cv2.rectangle(old_img, (x,y), (x+w, y+h), (255, 0, 0), 2)
boxes.sort(key=lambda i:i[1], reverse=True)
cv2.imshow('img',old_img)
cv2.waitKey(5000)
x,y,w,h = boxes[0]
img_crop = temp_img[y:y+h,x:x+w]
old_crop = img_crop.copy()
backup_crop = img_crop.copy()
cv2.imshow('img',img_crop)
cv2.waitKey(5000)

img_crop = cv2.GaussianBlur(img_crop,(3,3),0)
crop_gray = cv2.cvtColor(img_crop, cv2.COLOR_BGR2GRAY)
_, crop_bin = cv2.threshold(crop_gray,0,255,cv2.THRESH_OTSU)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(2,2))
crop_bin = cv2.dilate(crop_bin,kernel)
cv2.imshow('img',crop_bin)
cv2.waitKey(5000)

_, contours, _ = cv2.findContours(crop_bin,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
zi_box = []
for contour in contours:
    rect = cv2.boundingRect(contour)
    x,y,w,h = rect
    # if w*h < 200 or w*h>3000: continue
    if (h>1.5*w) and (h<3*w):
        zi_box.append([x,y,w,h])
        cv2.rectangle(old_crop, (x,y), (x+w, y+h), (0, 0, 255), 2)
cv2.imshow('img',old_crop)
cv2.waitKey(5000)
zi_box.sort(key=lambda i:i[0],reverse=False)
print(zi_box)

x,y,w,h= zi_box[1]
zi_crop = backup_crop[y:y+h,x:x+w]
print(zi_crop.shape)
cv2.imwrite('H.jpg',zi_crop)
cv2.imshow('img',zi_crop)
cv2.waitKey(5000)
cv2.destroyAllWindows()

import os
import cv2

template_dir = './refer1'
template_body = []
for cls_name in os.listdir(template_dir):
    template_body.extend([[cls_name,template_dir+'/'+cls_name+'/'+i] for i in os.listdir(template_dir+'/'+cls_name)])
# print(template_body[0])

img = cv2.imread('H.jpg',cv2.COLOR_BGR2GRAY)
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
w,h = img.shape
for index,item in enumerate(template_body):
    template = cv2.imread(item[1])
    template = cv2.cvtColor(template,cv2.COLOR_BGR2GRAY)
    template = cv2.resize(template,(h,w))
    score = cv2.matchTemplate(img,template,cv2.TM_CCOEFF)[0,0]
    template_body[index].insert(0,score)
# print(template_body[0])
template_body.sort(key=lambda i:i[0],reverse=True)
print(template_body[0:3])

H.jpg

[[3810410.2, '桂', './refer1/桂/桂_70.jpg'],
 [3645890.0, 'B', './refer1/B/58.jpg'], 
[3608947.2, '0', './refer1/0/n24.jpg']]

9.jpg

[[3954204.5, '9', './refer1/9/10-0.jpg'], 
[3737860.2, '9', './refer1/9/3_0.855008_gray_12816_5036_step5_recog_3_9_0.976258_0.834708.jpg'],
 [3673604.2, '9', './refer1/9/5_0.950823_gray_3683_1554_step5_recog_5_9_0.991150_0.942408.jpg']]

沪.jpg

[[3371885.8, '沪', './refer1/沪/沪_220.jpg'], 
[3197117.8, '沪', './refer1/沪/沪_222.jpg'], 
[3157204.8, '沪', './refer1/沪/沪_221.jpg']]

TM_CCOEFF

import cv2
import numpy as np

old_img = cv2.imread('che1.png')
img = cv2.resize(old_img,(100,120))
template = cv2.resize(old_img,(50,60))
result = cv2.matchTemplate(img,template,cv2.TM_CCOEFF)
print(result.shape)
print(result[0:2,0:2])

i_rows,i_cols,_ = img.shape
h,w,_ = template.shape
diy = np.zeros((i_rows-h+1,i_cols-w+1))

template_mean = np.mean(template,axis=(0,1),keepdims=True)
template_new = template - template_mean
template_line = template_new.reshape(-1,)

for row_index in range(i_rows-h+1):
    for col_index in range(i_cols-w+1):
        img_crop = img[row_index:row_index+h,col_index:col_index+w]
        img_crop_mean = np.mean(img_crop,axis=(0,1),keepdims=True)
        img_crop_new = img_crop - img_crop_mean
        pixes_line = img_crop_new.reshape(-1,)
        diy[row_index,col_index] = np.dot(pixes_line,template_line)
print(diy.shape)
print(diy[0:2,0:2])

输出效果

(61, 51)
[[4881797. 4958400.]
 [5048702. 5272232.]]
(61, 51)
[[4881795.811      4958397.90766667]
 [5048704.82233333 5272229.10133333]]

GRAY

import cv2
import numpy as np

old_img = cv2.imread('che1.png')
old_img = cv2.cvtColor(old_img,cv2.COLOR_BGR2GRAY)

img = cv2.resize(old_img,(100,120))
template = cv2.resize(old_img,(50,60))
result = cv2.matchTemplate(img,template,cv2.TM_CCOEFF)
print(result.shape)
print(result[10:12,10:12])
# print(result)

i_rows,i_cols = img.shape
h,w = template.shape
diy = np.zeros((i_rows-h+1,i_cols-w+1))

template_mean = np.sum(template)/(w*h)
template_new = template - template_mean
template_line = template_new.reshape(-1,)

for row_index in range(i_rows-h+1):
    for col_index in range(i_cols-w+1):
        img_crop = img[row_index:row_index+h,col_index:col_index+w]
        img_crop_mean = np.sum(img_crop)/(w*h)
        img_crop_new = img_crop - img_crop_mean
        pixes_line = img_crop_new.reshape(-1,)
        diy[row_index,col_index] = np.dot(pixes_line,template_line)
print(diy.shape)
print(diy[10:12,10:12])
# print(diy)

输出效果

(61, 51)
[[1911522.9 2079905.1]
 [1861463.6 2019491.5]]
(61, 51)
[[1911525.84533333 2079907.06933333]
 [1861462.65066667 2019491.51733333]]

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/721808.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

《SelectDB 新一代日志存储分析平台解决方案》白皮书重磅发布|立即下载

随着信息技术的飞速进步&#xff0c;企业面临着前所未有的系统复杂性和数据挑战。在此背景下&#xff0c;日志数据成为了企业洞察系统内部状态、监控网络安全以及分析业务动态的宝贵资源&#xff0c;构建高效的日志存储与分析平台至关重要。 作为基于 Apache Doris 打造的现代…

17. 一个I/O项目:构建命令行程序(下)

目录 五、采用测试驱动开发完善库的功能5.1 编写失败测试用例5.2 编写成功测试用例5.3 在run函数中打印搜索到的行 六、添加大小写不敏感功能七、将错误信息输出到标准错误八、附录完整代码 五、采用测试驱动开发完善库的功能 5.1 编写失败测试用例 在lib.rs中写一个简单的se…

JAVAEE之网络原理(2)_传输控制协议(TCP)、概念、格式、确认应答及超时重传机制

前言 在上一节中&#xff0c;我们介绍了 UDP (用户数据报) 的相关知识&#xff0c;在这一节中我们将继续介绍传输层中另一种更为重要的协议。 一、什么是TCP协议&#xff1f; 1.1 TCP 基本概念 TCP协议全称&#xff1a;传输控制协议&#xff08;TCP&#xff0c;Transmission C…

Vatee万腾平台:创新科技,助力企业腾飞

在全球化竞争日益激烈的今天&#xff0c;企业如何借助科技力量实现转型升级&#xff0c;已成为摆在众多企业家面前的重大课题。Vatee万腾平台凭借其卓越的创新科技和专业的服务能力&#xff0c;成为众多企业实现腾飞的得力助手。 一、创新科技&#xff0c;引领企业前行 Vatee万…

计算机网络实验(9):路由器的基本配置和单臂路由配置

一、 实验名称 路由器的基本配置和单臂路由配置 二、实验目的&#xff1a; &#xff08;1&#xff09;路由器的基本配置&#xff1a; 掌握路由器几种常用配置方法&#xff1b; 掌握采用Console线缆配置路由器的方法&#xff1b; 掌握采用Telnet方式配置路由器的方法&#…

Spring事务 和 事务传播机制

这里的 事务 和之前 MySQL的事务 一样&#xff0c;都是表示将⼀组操作封装成⼀个执⾏单元&#xff08;封装到⼀起&#xff09;&#xff0c;要么全部成功&#xff0c;要么全部失败。 Spring 中事务的实现 1. 编程式事务&#xff08;手动档&#xff09;。 package com.example.…

Java线程池基本概念

全局和局部线程池 全局线程池 在Spring框架中&#xff0c;全局线程池如ThreadPoolTaskExecutor通常是作为Spring Bean存在的&#xff0c;它们的生命周期由Spring容器管理。当Spring容器关闭时&#xff0c;这些线程池也会被适当地清理和关闭。因此&#xff0c;开发者通常不需要手…

MCK主机加固在防漏扫中的关键作用

在当今这个信息化飞速发展的时代&#xff0c;网络安全成为了企业不可忽视的重要议题。漏洞扫描&#xff0c;简称漏扫&#xff0c;是一种旨在发现计算机系统、网络或应用程序中潜在安全漏洞的技术手段。通过自动化工具&#xff0c;漏扫能够识别出系统中存在的已知漏洞&#xff0…

调度算法-进程调度算法

发⽣ CPU 调度通常有以下情况&#xff1a; 1. 当进程从运⾏状态转到等待状态&#xff1b;2. 当进程从运⾏状态转到就绪状态&#xff1b;3. 当进程从等待状态转到就绪状态&#xff1b;4. 当进程从运⾏状态转到终⽌状态 常⻅的调度算法&#xff1a; 先来先服务调度算法最短作业…

Airtest初使用

https://airtest.doc.io.netease.com/tutorial/2_Airtest_introduction/ 什么是Airtest Airtest是一款基于Python语言、跨平台的UI自动化测试框架&#xff0c;基于图像识别原理&#xff0c;比较适用于游戏和App。 它的主要特点包括&#xff1a; 跨平台支持&#xff1a;支持A…

打造精致UI界面:字体设计的妙招

字体设计是UI设计的关键模块之一。字体设计是否有效可能直接实现或破坏整个UI界面。那么&#xff0c;界面设计的字体设计有哪些规范呢&#xff1f;如何设计细节字体&#xff1f;本文将解释字体设计规范的可读性、可读性和可用性&#xff0c;并介绍UI界面中的字体设计技巧。 如…

团队管理的三个要点,打造高执行力团队

一、明确目标与责任 明确的目标与责任是团队高效运作的基石。只有当团队成员对目标有清晰的认识&#xff0c;并明确自己的责任时&#xff0c;才能形成强大的合力&#xff0c;推动团队不断前进。 1、目标设定 目标应该具体、可衡量、有挑战性但可实现。项目经理可以与团队成员…

Nginx Proxy 代理测试

目录 https://blog.csdn.net/Lzcsfg/article/details/139781909 一. 实验准备 二. 配置反向代理 三. 配置二层代理 解释流程 一. 实验准备 关闭防火墙和selinux&#xff0c;准备三台同一网段的虚拟机 localhostRoucky_linux9.4192.168.226.20localhostRoucky_linux9.419…

【2024泰迪杯】C 题:竞赛论文的辅助自动评阅 26页及31页2篇完整论文及Python 代码实现

【2024泰迪杯】C 题&#xff1a;竞赛论文的辅助自动评阅 26页及31页完整论文及Python 代码实现 相关链接 【2024泰迪杯】A 题&#xff1a;生产线的故障自动识别与人员配置 Python代码实现 【2024泰迪杯】B 题&#xff1a;基于多模态特征融合的图像文本检索Python代码实现 【2…

基于PHP的草莓种植信息管理系统

有需要请加文章底部Q哦 可远程调试 基于PHP的草莓种植管理系统 一 介绍 此草莓种植管理系统基于原生PHP开发&#xff0c;数据库mysql&#xff0c;前端采用jquery.js和kindeditor在线HTML编辑器。系统角色分为用户和管理员。 技术栈&#xff1a;phpmysqljquery.jsphpstudyvsco…

云计算【第一阶段(16)】安装及管理程序

一、linux 应用程序基础 当我们主机安装linux操作系统 时候&#xff0c;也会同时安装一些软件或网络服务等等&#xff0c;但是随着系统一起安装的软件包毕竟他是少数的&#xff0c; 能够实现的功能也是有限的&#xff0c;那么我们相拥为主机提供更多更丰富的功能的时候&#x…

注意力机制和Transformer模型各部分功能解释

文章目录 Transformer1、各部分功能解释2、通过例子解释a.输入预处理位置编码b.Encoder 的处理c.Decoder的输入Decoder的工作流程d.输出预测总结 Attention代码和原理理解 Transformer 运行机理&#xff1a; &#xff08;1&#xff09;假设我们需要进行文本生成任务。我们将已…

Java17 --- redis7缓存双写一致性

一、缓存双写一致性 如果redis中有数据&#xff1a;需要和数据库中的值相同。如果redis中没有数据&#xff1a;数据库中的值要是最新值&#xff0c;且准备回写redis。只读缓存。读写缓存&#xff1a;①、同步直写策略&#xff1a;写数据库后也同步写redis缓存&#xff0c;缓存…

计算机网络(谢希仁第六版)| 课后习题与答案 | 物理层 | 题目知识点详细分析

计算机网络&#xff08;谢希仁第六版&#xff09;课后习题与答案 物理层 博客只对老师给的重点进行整理&#xff0c;完整的课后习题答案见Gitee下载&#xff1a;《计算机网络教程&#xff08;第6版&#xff09;&#xff08;微课版&#xff09;》习题答案 2-5 请画出数据流1 0 1…

Java基础学习-流程控制语句-顺序结构-分支结构-循环结构

目录 顺序结构&#xff1a; 分支结构&#xff1a; if语句&#xff1a; 第一种格式&#xff1a; if第二种格式&#xff1a; 案例练习 if第三种格式&#xff1a; switch语句&#xff1a; 格式&#xff1a; switch其他知识点&#xff1a; 循环结构&#xff1a; for循环…