#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车牌精确定位的更多相关文章

  1. Selenuim+Python之元素定位总结及实例说明

    网页自动化最基本的要求就是要定位到各个元素,然后才能对该元素进行各种操作(输入,点击,清除,提交等),所以笔者今天来总结下Selenuim+Python最基本的几种定位方式及实例说明,希望能帮助到大家 ...

  2. HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth

    HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对 ...

  3. 利用flash精确定位asp.net的图像热点区域

    Asp.net的热点区域控件非常有用,但是对于热点区域如何精确定位,设定矩形,圆和多边形要素点的位置,用flash能够精确定位,在flash中制作热点区域的部分,可以是矩形,图形或者文字,然后对于这部 ...

  4. CSliderCtrl鼠标点击精确定位

    实现CSliderCtrl的子类CXXCtrl 响应左键按下消息 ON_WM_LBUTTONDOWN() void CXXCtrl::OnLButtonDown(UINT nFlags, CPoint ...

  5. Selenium2+python自动化28-table定位

    前言 在web页面中经常会遇到table表格,特别是后台操作页面比较常见.本篇详细讲解table表格如何定位. 一.认识table 1.首先看下table长什么样,如下图,这种网状表格的都是table ...

  6. Python Appium 元素定位方法简单介绍

    Python  Appium  元素定位 常用的八种定位方法(与selenium通用) # id定位 driver.find_element_by_id() # name定位 driver.find_ ...

  7. Unity3D中使用Profiler精确定位性能热点的优化技巧

    本文由博主(SunboyL)原创,转载请注明出处:http://www.cnblogs.com/xsln/p/BeginProfiler.html 简介 在使用Profiler定位代码的性能热点时,很 ...

  8. window.location.hash 页面跳转,精确定位,实例展示:

    window.location.hash 页面跳转,精确定位,实例展示: (1).index.phtml,页面用于传参 <script id="bb_list_template&quo ...

  9. Selenium2+python自动化28-table定位【转载】

    前言 在web页面中经常会遇到table表格,特别是后台操作页面比较常见.本篇详细讲解table表格如何定位. 一.认识table 1.首先看下table长什么样,如下图,这种网状表格的都是table ...

随机推荐

  1. No qualifying bean of type xxx' available 的一种解决方法

    获取bean Class beanClass = Class.forName(event.className); FilterEvent filterEvent = (FilterEvent)Bean ...

  2. ForkJoinPool详解

    本文的主要目的是介绍 ForkJoinPool 的适用场景,实现原理,以及示例代码. 说在前面可以说是说明,也可以说下面是结论: ForkJoinPool 不是为了替代 ExecutorService ...

  3. php内置函数分析之ucwords()

    PHP_FUNCTION(ucwords) { zend_string *str; char *delims = " \t\r\n\f\v"; register char *r, ...

  4. django 多表查询并返回结果

    (不喜勿喷,个人记录) 问题,有两张关联的表,表B的api_id关联表A的id 我想在页面上返回两张表查询之后的共同结果? 因为两张表的id是一样的,就先获取到表A的对象,然后拿表A的对象id当做表B ...

  5. Git关联JIRA的issue

    指导文章 http://www.51testing.com/html/30/n-3724930.html http://{$host_url}/help/user/project/integratio ...

  6. 【leetcode】1079. Letter Tile Possibilities

    题目如下: You have a set of tiles, where each tile has one letter tiles[i]printed on it.  Return the num ...

  7. OC中保存自定义类型对象的持久化方法

    OC中如果要将自定义类型的对象保存到文件中,必须进行以下三个条件: 想要把存放自定义类型的数组进行 持久化(就是将内存中的临时数据以文件<数据库等>的形式写到磁盘上)必须满足: 1. 自定 ...

  8. linux运维、架构之路-内网NTP时间服务器

    一.环境 [root@m01 tmp]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@m01 tmp]# hostname -I ...

  9. win7连接无线网出现黄色感叹号怎么办?

    用win7连接无线网,出现黄色感叹号: 1.IP冲突,“网络中心”-“无线网属性”,手动改下IP,子网掩码,网关,DNS 2.360断网急救箱修复问题

  10. SYSTEM32 下的几乎所有文件的简单说明(原由无忧启动论坛老毛桃出)

    SYSTEM32 下的几乎所有文件的简单说明(原由无忧启动论坛http://bbs.wuyou.com老毛桃出): clui.dll .....Security Descriptor Editor,没 ...