传统车牌识别

news2024/10/7 0:10:57

主要参考: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.coloradmin.cn/o/1836391.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

三星SAINT-D技术引领HBM内存堆叠革命

三星电子即将在今年推出一项革命性技术&#xff0c;允许在CPU或GPU上堆叠高带宽内存&#xff08;HBM&#xff09;&#xff0c;根据韩国经济日报的报道&#xff0c;这一消息在圣何塞举办的三星晶圆代工论坛2024上公布&#xff0c;并得到业内消息人士证实。这项3D封装技术为2025年…

ESP32蓝牙BLE连接米家温湿度计

ESP32蓝牙BLE连接米家温湿度计 文章目录 ESP32蓝牙BLE连接米家温湿度计简介需要准备的东西软件调试代码实现修改查找的名称 修改需要连接的服务和属性添加解析数据的代码 上电演示提示 简介 最近在学习低功耗蓝牙BLE(Bluetooth Low Energy)&#xff0c;刚好手里有个米家蓝牙温…

总结一下 C# 如何自定义特性 Attribute 并进行应用

前言 Attribute&#xff08;特性&#xff09;是一种用于为程序元素&#xff08;如类、方法、属性等&#xff09;提供元数据信息的方法。 特性是一种声明式的信息&#xff0c;附加到程序元素上&#xff0c;提供额外的数据用于描述和控制这些元素的行为。 在编译和运行时&…

WMS系统调拨盘点功能:优化仓储管理效率

一、调拨功能概述 WMS系统的调拨功能是指仓库内部或者不同仓库之间对商品进行转移的过程。调拨的目的在于平衡库存、优化存储空间和提高物流效率。调拨功能主要包括以下几个方面&#xff1a; 1. 调拨申请&#xff1a;根据业务需求&#xff0c;仓库管理员可以发起调拨申请&…

软件设计不是CRUD(23):在流式数据处理系统中进行业务抽象落地——详细编码

&#xff08;接上文《软件设计不是CRUD&#xff08;22&#xff09;&#xff1a;在流式数据处理系统中进行业务抽象落地——设计思考》&#xff09; 4、详细设计 项目开发初期&#xff0c;有两种测速雷达和对应的摄像头需要接入&#xff0c;分别是STC500型测速雷达和TTS400型测…

《UNIX环境高级编程》第三版(电子工业出版社出品)——两年磨一剑的匠心译作

历时两年&#xff0c;《UNIX环境高级编程》的翻译工作终于落下帷幕。这一路走来&#xff0c;真可谓是如鱼饮水&#xff0c;冷暖自知。还记得最初看到招募译者消息的那一刻&#xff0c;内心的激动难以言表。我毫不犹豫地报名&#xff0c;而后经历了试译、海选等激烈的角逐&#…

TestProject Python SDK入门

2024软件测试面试刷题&#xff0c;这个小程序&#xff08;永久刷题&#xff09;&#xff0c;靠它快速找到工作了&#xff01;&#xff08;刷题APP的天花板&#xff09;-CSDN博客跳槽涨薪的朋友们有福了&#xff0c;今天给大家推荐一个软件测试面试的刷题小程序。​编辑https://…

怎么提取视频中的音频?别错过这6个音频提取方法了!(全新)

您是否曾经发现过一个音乐很棒的视频&#xff0c;并想从视频中提取音频&#xff1f;如今&#xff0c;关于提取mp4视频中的音频需求越来越常见。例如&#xff0c;您可能想从mp4格式的电影中提取音频&#xff0c;将音乐用作手机铃声&#xff0c;或在自己的视频项目中使用视频中的…

C#唯一进程的处理Winform/WPF

C#唯一进程的处理 1.使用进程&#xff08;Process&#xff09;判断winformWPF执行效果&#xff1a; 2.使用互斥体&#xff08;Metux&#xff09;实现winformWPF实现效果&#xff1a; 在C#客户端&#xff08;Winform/WPF&#xff09;开发过程中&#xff0c;有的情况需要确保程序…

零基础入门学用Arduino 第四部分(一)

重要的内容写在前面&#xff1a; 该系列是以up主太极创客的零基础入门学用Arduino教程为基础制作的学习笔记。个人把这个教程学完之后&#xff0c;整体感觉是很好的&#xff0c;如果有条件的可以先学习一些相关课程&#xff0c;学起来会更加轻松&#xff0c;相关课程有数字电路…

Microsoft Visual C++ Redistributable 【安装包】【高速下载】

方法1、可以从官方下载&#xff0c;如下图 方法2 已经下载好并且已经整理好了2008--2022的所有版本点击下方链接即可高速下载 如果是win7-win8-win10-win11直接可以下载2015--2022版本&#xff0c;xp需要下载2015之前的 点击链接Microsoft Visual C Redistributable官方版本…

茶艺师服务师傅小程序APP源码(APP+小程序+公众号+H5)

&#x1f375;茶艺师服务小程序&#xff1a;品味生活的茶艺新体验&#x1f331; &#x1f33f;一、引言&#xff1a;茶艺师服务小程序&#xff0c;让生活更有味 在繁忙的生活中&#xff0c;品一杯香茗&#xff0c;感受茶文化的韵味&#xff0c;是许多人向往的休闲方式。然而&…

Android开发系列(四)Jetpack Compose之Button

在Jetpack Compose中&#xff0c;Button是一个常用的用户界面组件&#xff0c;用于执行某些操作或触发某些事件。Button控件是可触摸的&#xff0c;并且通常会显示一个文本或图标来表示其功能。 要在Jetpack Compose中创建一个Button&#xff0c;可以使用Button()函数&#xf…

C#——正则表达式详情

正则表达式 正则表达式: 列如判断一个字符串是不是手机号&#xff0c;或者密码是否包含大小写数字等这些要求&#xff0c;可以把这些条件写成一个表达式 创建正则表达式 string s1 "1234adsab1KHGFJD"; // 创建正则时需要在字符串前面加上 Regex r new Regex(&q…

序列化与反序列化漏洞实例

实验环境&#xff1a; 本次的序列化与反序列化漏洞为2021年强网杯上的一道比赛题目&#xff0c;我使用phpstudy集成环境将其测试环境搭建在了本地&#xff0c;如下。涉及的几个页面php为&#xff1a; index.php function.php myclass.php index.php : <?php // inde…

【Redis】java客户端(SpringData和jedis)

https://www.oz6.cn/articles/58 https://www.bilibili.com/video/BV1cr4y1671t/?p16 redis官网客户端介绍&#xff1a;https://redis.io/docs/latest/develop/connect/clients/ jedis maven引入依赖 <dependencies><!--引入Jedis依赖--><dependency><…

统计学一(术语,正态)

目录 一&#xff0c;常用术语 二&#xff0c;正态分布&#xff08;Normal Distribution&#xff09; 三&#xff0c;中心极限定理(Central Limit Theorem) 一&#xff0c;常用术语 population(族群)&#xff1a;要统计的总的 populationSize(族群数量)&#xff1a;要统计的总…

CSS【实战】抽屉动画

效果预览 技术要点 实现思路 元素固定布局&#xff08;fixed&#xff09;在窗口最右侧外部js 定时器改变元素的 right 属性&#xff0c;控制元素移入&#xff0c;移出 过渡动画 transition transition: 过渡的属性 过渡的持续时间 过渡时间函数 延迟时间此处改变的是 right …

【进阶篇-Day3:JAVA接口新特性、代码块、内部类、Lambda表达式、组件等的介绍】

目录 1、接口新特性1.1 JDK8的新特性1.2 JDK9的新特性 2、代码块2.1 代码块的定义2.2 代码块的分类 3、内部类3.1 内部类的定义3.2 内部类成员访问3.3 学习内部类的原因3.4 内部类的分类3.4.1 成员内部类3.4.2 静态内部类3.4.3 局部内部类3.4.4 匿名内部类&#xff08;1&#x…

使用自签名 TLS 将 Dremio 连接到 MinIO

Dremio 是一个开源的分布式分析引擎&#xff0c;为数据探索、转换和协作提供简单的自助服务界面。Dremio 的架构建立在 Apache Arrow&#xff08;一种高性能列式内存格式&#xff09;之上&#xff0c;并利用 Parquet 文件格式实现高效存储。有关 Dremio 的更多信息&#xff0c;…