资源简介
算法思想来自于网上资源,先使用图像边缘和车牌颜色定位车牌,再识别字符。算法代码只有500行,测试中发现,车牌定位算法的参数受图像分辨率,色偏,车距影响,有的车型识别效果有待提高。
代码片段和文件信息
import cv2
import numpy as np
from numpy.linalg import norm
import sys
import os
import json
SZ = 20 #训练图片长宽
MAX_WIDTH = 1000 #原始图片最大宽度
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 ix 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)
gy = cv2.Sobel(img cv2.CV_32F 0 1)
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[:1010:] bin[10:10:]
mag_cells = mag[:10:10] mag[10::10] mag[:1010:] 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“ “蒙“
“zh_min“ “闽“
“zh_ning“ “宁“
“zh_qing“ “靑“
“zh_qiong“ “琼“
“zh_shan“ “陕“
“zh_su“ “苏“
“zh_sx“ “晋“
“zh_wan“ “皖“
“zh_xiang“ “湘“
“zh_xin“ “新“
“zh_yu“ “豫“
“zh_yu1“ “渝“
“zh_yue“ “粤“
“zh_yun“ “云“
“zh_zang“ “藏“
“zh_zhe“ “浙“
]
class StatModel(object):
def load(self fn):
self.model = self.model.load(fn)
def save(self fn):
self.model.save(fn)
class SVM(StatModel):
def __init__(self C = 1 gamma = 0.5):
self.model = cv2.ml.SVM_create()
self.model.setGamma(gamma)
self.model.setC(C)
self.model.setKernel(cv2.ml.SVM_RBF)
self.model.setT
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 1157 2018-05-26 22:39 车牌识别\.gitignore
....... 262 2018-05-26 22:39 车牌识别\config.js
....... 1060 2018-05-26 22:39 车牌识别\LICENSE
....... 18184 2018-05-26 22:39 车牌识别\predict.py
....... 1804 2018-05-26 22:39 车牌识别\README.md
....... 513442 2018-05-26 22:39 车牌识别\Screenshots\3.png
....... 335454 2018-05-26 22:39 车牌识别\Screenshots\5.png
....... 4640 2018-05-26 22:39 车牌识别\surface.py
....... 4595678 2018-05-26 22:39 车牌识别\svm.dat
....... 3645216 2018-05-26 22:39 车牌识别\svmchinese.dat
....... 4543569 2018-05-26 22:39 车牌识别\test\1.jpg
....... 2718121 2018-05-26 22:39 车牌识别\test\2.jpg
....... 62588 2018-05-26 22:39 车牌识别\test\cAA662F.jpg
....... 27089 2018-05-26 22:39 车牌识别\test\car3.jpg
....... 25090 2018-05-26 22:39 车牌识别\test\car4.jpg
....... 28604 2018-05-26 22:39 车牌识别\test\car5.jpg
....... 27744 2018-05-26 22:39 车牌识别\test\car7.jpg
....... 24073 2018-05-26 22:39 车牌识别\test\lLD9016.jpg
....... 52515 2018-05-26 22:39 车牌识别\test\wA87271.jpg
....... 116063 2018-05-26 22:39 车牌识别\test\wATH859.jpg
....... 141788 2018-05-26 22:39 车牌识别\test\wAUB816.jpg
....... 3336217 2018-05-26 22:39 车牌识别\train\chars2.7z
....... 1099009 2018-05-26 22:39 车牌识别\train\charsChinese.7z
目录 0 2018-05-26 22:39 车牌识别\Screenshots
目录 0 2018-05-26 22:39 车牌识别\test
目录 0 2018-05-26 22:39 车牌识别\train
目录 0 2018-05-26 22:39 车牌识别
----------- --------- ---------- ----- ----
21319367 27
............此处省略0个文件信息
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论