python车牌精确定位
#coding=utf-8
import cv2
# 使用的是HyperLPR已经训练好了的分类器
watch_cascade = cv2.CascadeClassifier('model/cascade.xml')
# 先读取图片
image = cv2.imread("D:\\Downloads\\License-Plate-Recognition-master\\test\\car5.jpg")
def detectPlateRough(image_gray,resize_h = 720,en_scale =1.08 ,top_bottom_padding_rate = 0.05):
if top_bottom_padding_rate>0.2:
print("error:top_bottom_padding_rate > 0.2:",top_bottom_padding_rate)
exit(1)
height = image_gray.shape[0]
padding = int(height*top_bottom_padding_rate)
scale = image_gray.shape[1]/float(image_gray.shape[0])
image = cv2.resize(image_gray, (int(scale*resize_h), resize_h))
image_color_cropped = image[padding:resize_h-padding,0:image_gray.shape[1]]
image_gray = cv2.cvtColor(image_color_cropped,cv2.COLOR_RGB2GRAY)
watches = watch_cascade.detectMultiScale(image_gray, en_scale, 2, minSize=(36, 9),maxSize=(36*40, 9*40))
cropped_images = []
for (x, y, w, h) in watches:
#cv2.rectangle(image_color_cropped, (x, y), (x + w, y + h), (0, 0, 255), 1)
x -= w * 0.14
w += w * 0.28
y -= h * 0.15
h += h * 0.3
#cv2.rectangle(image_color_cropped, (int(x), int(y)), (int(x + w), int(y + h)), (0, 0, 255), 1)
cropped = cropImage(image_color_cropped, (int(x), int(y), int(w), int(h)))
cropped_images.append([cropped,[x, y+padding, w, h]])
#cv2.imshow("imageShow", cropped)
#cv2.waitKey(0)
return cropped_images
def cropImage(image,rect):
cv2.imshow("imageShow", image)
cv2.waitKey(0)
x, y, w, h = computeSafeRegion(image.shape,rect)
cv2.imshow("imageShow", image[y:y+h,x:x+w])
cv2.waitKey(0)
return image[y:y+h,x:x+w]
def computeSafeRegion(shape,bounding_rect):
top = bounding_rect[1] # y
bottom = bounding_rect[1] + bounding_rect[3] # y + h
left = bounding_rect[0] # x
right = bounding_rect[0] + bounding_rect[2] # x + w
min_top = 0
max_bottom = shape[0]
min_left = 0
max_right = shape[1]
#print(left,top,right,bottom)
#print(max_bottom,max_right)
if top < min_top:
top = min_top
if left < min_left:
left = min_left
if bottom > max_bottom:
bottom = max_bottom
if right > max_right:
right = max_right
return [left,top,right-left,bottom-top]
images = detectPlateRough(image,image.shape[0],top_bottom_padding_rate=0.1)
print("检测到车牌数", len(images))
效果:
python车牌精确定位的更多相关文章
- Selenuim+Python之元素定位总结及实例说明
网页自动化最基本的要求就是要定位到各个元素,然后才能对该元素进行各种操作(输入,点击,清除,提交等),所以笔者今天来总结下Selenuim+Python最基本的几种定位方式及实例说明,希望能帮助到大家 ...
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth
HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对 ...
- 利用flash精确定位asp.net的图像热点区域
Asp.net的热点区域控件非常有用,但是对于热点区域如何精确定位,设定矩形,圆和多边形要素点的位置,用flash能够精确定位,在flash中制作热点区域的部分,可以是矩形,图形或者文字,然后对于这部 ...
- CSliderCtrl鼠标点击精确定位
实现CSliderCtrl的子类CXXCtrl 响应左键按下消息 ON_WM_LBUTTONDOWN() void CXXCtrl::OnLButtonDown(UINT nFlags, CPoint ...
- Selenium2+python自动化28-table定位
前言 在web页面中经常会遇到table表格,特别是后台操作页面比较常见.本篇详细讲解table表格如何定位. 一.认识table 1.首先看下table长什么样,如下图,这种网状表格的都是table ...
- Python Appium 元素定位方法简单介绍
Python Appium 元素定位 常用的八种定位方法(与selenium通用) # id定位 driver.find_element_by_id() # name定位 driver.find_ ...
- Unity3D中使用Profiler精确定位性能热点的优化技巧
本文由博主(SunboyL)原创,转载请注明出处:http://www.cnblogs.com/xsln/p/BeginProfiler.html 简介 在使用Profiler定位代码的性能热点时,很 ...
- window.location.hash 页面跳转,精确定位,实例展示:
window.location.hash 页面跳转,精确定位,实例展示: (1).index.phtml,页面用于传参 <script id="bb_list_template&quo ...
- Selenium2+python自动化28-table定位【转载】
前言 在web页面中经常会遇到table表格,特别是后台操作页面比较常见.本篇详细讲解table表格如何定位. 一.认识table 1.首先看下table长什么样,如下图,这种网状表格的都是table ...
随机推荐
- Oracle Internals Notes Redo Write Triggers
There are four conditions that cause LGWR to perform a redo write. When LGWR is idle, it sleeps on a ...
- PHP与CI学习笔记
CodeIgniter框架学习 安装 下载好包后,解压复制 system 和 application 目录到网站目录下 配置 配置目录 打开index.php设置好 $system_path . $a ...
- [HYSBZ - 3252] 攻略
问题描述 题目简述:树版[k取方格数] 众所周知,桂木桂马是攻略之神,开启攻略之神模式后,他可以同时攻略k部游戏.今天他得到了一款新游戏<XX 半岛>,这款游戏有n个场景(scene),某 ...
- ES6基本用法
es6是JS(JavaScript)的下一个版本. 新增了let命令,用来声明变量.变量在第一个花括号内有用,先声明后引用.不允许重复声明.存在暂时性死区. const声明一个只读的常量.一旦声明,常 ...
- Jmeter的JDBC请求执行多条SQL语句
注:有mysqlconnector/j 3.1.1以上版本才支持执行多条sql语句 1. 下载jdbc驱动为了连接Mysql数据库,还需要有个jdbc驱动:mysql-connector-ja ...
- php strcspn()函数 语法
php strcspn()函数 语法 作用:输出在字符串中找到某字符之前查找的字符数.直线电机参数 语法:strcspn(string,char,start,length) 参数: 参数 描述 str ...
- PHPcms编辑器如何粘贴带格式的word文档
在之前在工作中遇到在富文本编辑器中粘贴图片不能展示的问题,于是各种网上扒拉,终于找到解决方案,在这里感谢一下知乎中众大神以及TheViper. 通过知乎提供的思路找到粘贴的原理,通过TheViper找 ...
- MatrixTraceTransform主要逻辑在transform方法中
@Override public void transform(TransformInvocation transformInvocation) throws TransformException, ...
- sqlalchemy.exc.NoForeignKeysError:Can't find any foreign key relationships between
这句话的意思是,两张表之间的外键找不到,首先看看外键设置正确了没,如果外键没问题,看看是不是_tablename_设置了没,就是再model中,定义类的时候,表格名称要_tablename_设置一下, ...
- 穿戴-智能穿戴-ProjectGlass:谷歌眼镜(Google Project Glass)
ylbtech-穿戴-智能穿戴-ProjectGlass:谷歌眼镜(Google Project Glass) 谷歌眼镜(Google Project Glass)是由谷歌公司于2012年4月发布的一 ...