资源简介
这是基于python和opencv的车牌号码识别,用到了机器学习和支持向量机,代码里各个部分的功能已经标记好了注释,清晰明了。可以直接解码使用,含有案例,也可以提供PPT报告
代码片段和文件信息
import cv2
import numpy as np
from numpy.linalg import norm#求范数
import sys
import os
import json
SZ = 20 # 训练图片长宽
MAX_WIDTH = 1000 # 原始图片最大宽度
MAX_HEIGHT = 750 # 原始图片最大高度度
Min_Area = 2000 # 车牌区域允许最大面积
PROVINCE_START = 1000
# 读取图片文件
def imreadex(filename):
return cv2.imdecode(np.fromfile(filename dtype=np.uint8) cv2.IMREAD_COLOR)
#函数从指定的内存缓存中读取数据,并把数据转化(解码)成图像格式,主要用于从网络传输数据中恢复出图像。
#函数读回数据时需要指定的类型,并对数组的形状进行指定的修改。
def point_limit(point):
if point[0] < 0:
point[0] = 0
if point[1] < 0:
point[1] = 0
# 根据设定的阈值和图片直方图,找出波峰,用于分隔字符
def find_waves(threshold histogram):
up_point = -1 # 上升点
is_peak = False
if histogram[0] > threshold:
up_point = 0
is_peak = True
wave_peaks = []
for i x in enumerate(histogram):
if is_peak and x < threshold:
if i - up_point > 2:
is_peak = False
wave_peaks.append((up_point i))
elif not is_peak and x >= threshold:
is_peak = True
up_point = i
if is_peak and up_point != -1 and i - up_point > 4:
wave_peaks.append((up_point i))
return wave_peaks
# 根据找出的波峰,分隔图片,从而得到逐个字符图片
def seperate_card(img waves):
part_cards = []
for wave in waves:
part_cards.append(img[: wave[0]:wave[1]])
return part_cards
# 来自opencv的sample,用于svm训练并进行仿射变换,允许图形任意倾斜,而且允许图形在两个方向上任意伸缩的变换。
def deskew(img):
m = cv2.moments(img)#表示图像的矩,矩可以理解为图像的各类几何特征。矩中包含了很多轮廓的特征信息。
if abs(m[‘mu02‘]) < 1e-2:
return img.copy()
skew = m[‘mu11‘] / m[‘mu02‘]
M = np.float32([[1 skew -0.5 * SZ * skew] [0 1 0]])
img = cv2.warpAffine(img M (SZ SZ) flags=cv2.WARP_INVERSE_MAP | cv2.INTER_LINEAR) # 仿射变换。。
return img
# 来自opencv的sample,用于svm训练 返回直方图
def preprocess_hog(digits):
samples = []
for img in digits:
gx = cv2.Sobel(img cv2.CV_32F 1 0)#进行sobel边缘检测,
gy = cv2.Sobel(img cv2.CV_32F 0 1)#32位浮点数
mag ang = cv2.cartToPolar(gx gy)#笛卡尔坐标转换为直角坐标
bin_n = 16
bin = np.int32(bin_n * ang / (2 * np.pi))
bin_cells = bin[:10 :10] bin[10: :10] bin[:10 10:] bin[10: 10:]
mag_cells = mag[:10 :10] mag[10: :10] mag[:10 10:] mag[10: 10:]
hists = [np.bincount(b.ravel() m.ravel() bin_n) for b m in zip(bin_cells mag_cells)]
hist = np.hstack(hists)
# transform to Hellinger kernel
eps = 1e-7
hist /= hist.sum() + eps
hist = np.sqrt(hist)
hist /= norm(hist) + eps
samples.append(hist)
return np.float32(samples)
# 不能保证包括所有省份
provinces = [
“zh_cuan“ “川“
“zh_e“ “鄂“
“zh_gan“ “赣“
“zh_gan1“ “甘“
“zh_gui“ “贵“
“zh_gui1“ “桂“
“zh_hei“ “黑“
“zh_hu“ “沪“
“zh_ji“ “冀“
“zh_jin“ “津“
“zh_jing“ “京“
“zh_jl“ “吉“
“zh_liao“ “辽“
“zh_lu“ “鲁“
“zh_meng“ “蒙“
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-11-03 22:00 aa0930762c66134157916b8c84ea5c6a\
目录 0 2019-11-03 22:00 aa0930762c66134157916b8c84ea5c6a\.idea\
文件 464 2019-11-03 20:49 aa0930762c66134157916b8c84ea5c6a\.idea\aa0930762c66134157916b8c84ea5c6a.iml
目录 0 2019-11-03 22:00 aa0930762c66134157916b8c84ea5c6a\.idea\inspectionProfiles\
文件 174 2019-11-03 20:49 aa0930762c66134157916b8c84ea5c6a\.idea\inspectionProfiles\profiles_settings.xm
文件 192 2019-11-03 20:49 aa0930762c66134157916b8c84ea5c6a\.idea\misc.xm
文件 323 2019-11-03 20:49 aa0930762c66134157916b8c84ea5c6a\.idea\modules.xm
文件 4188 2019-11-03 21:32 aa0930762c66134157916b8c84ea5c6a\.idea\workspace.xm
目录 0 2019-12-30 10:56 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\
文件 1157 2018-05-26 22:39 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\.gitignore
目录 0 2020-02-25 23:22 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\.idea\
目录 0 2018-11-21 19:36 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\.idea\inspectionProfiles\
文件 441 2019-11-11 08:42 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\.idea\License-Plate-Recognition-master.iml
文件 294 2019-11-11 08:42 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\.idea\misc.xm
文件 323 2018-11-19 23:48 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\.idea\modules.xm
文件 7015 2020-02-25 23:22 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\.idea\workspace.xm
文件 141788 2018-05-26 22:39 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\1.jpg
文件 24179 2019-11-03 21:03 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\3.jpg
文件 21732 2019-11-03 21:04 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\4.jpg
文件 44446 2019-11-03 21:06 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\7.jpg
文件 235952 2019-11-11 09:54 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\9.jpg
文件 10662178 2019-11-03 20:46 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\aa0930762c66134157916b8c84ea5c6a.zip
文件 434 2018-11-20 00:25 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\config.js
文件 1060 2018-05-26 22:39 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\LICENSE
文件 25386 2019-12-30 10:56 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\predict.py
文件 1804 2018-05-26 22:39 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\README.md
目录 0 2019-11-03 22:00 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\Screenshots\
文件 513442 2018-05-26 22:39 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\Screenshots\3.png
文件 335454 2018-05-26 22:39 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\Screenshots\5.png
文件 6398 2019-11-03 21:36 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\surface.py
文件 4595678 2018-05-26 22:39 aa0930762c66134157916b8c84ea5c6a\License-Plate-Recognition-master\svm.dat
............此处省略25个文件信息
评论
共有 条评论