python车牌矫正_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))

效果:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python车牌识别和去雾是两个不同的问题,我可以分别为您介绍。 1. Python车牌识别 Python车牌识别是一种利用计算机视觉技术,通过对车辆图片中车牌位置的提取、字符分割和识别等步骤,实现对车牌信息的自动识别。在Python中,常用的车牌识别库包括OpenCV、Tesseract-OCR等。 以下是一个简单的Python车牌识别的流程: 1. 车辆图片预处理:对车辆图片进行裁剪、缩放、灰度化、二值化、去噪等处理,以提高车牌定位的准确性。 2. 车牌定位:利用图像处理技术,如边缘检测、形态学操作等,找到车辆图片中车牌的位置。 3. 字符分割:将车牌图像中的字符分割出来,形成单独的字符图像。 4. 字符识别:使用OCR技术对字符图像进行识别,得到车牌号码。 如果您需要更加详细的介绍和代码实现,可以提供更具体的问题。 2. Python去雾 Python去雾是一种利用计算机视觉技术,通过对含有雾气的图片进行处理,使其变得更加清晰明亮。在Python中,常用的去雾方法包括暗通道先验方法、Retinex方法、直方图均衡化等。 以下是一个简单的Python去雾的流程: 1. 图片预处理:对含有雾气的图片进行灰度化和归一化处理。 2. 计算暗通道:根据暗通道先验原理,计算出图像的暗通道图像。 3. 估计大气光:根据暗通道图像,估计出图像中大气光的大小。 4. 进行去雾处理:根据大气光大小和图像原始像素值计算出去雾后的像素值,并对其进行调整。 如果您需要更加详细的介绍和代码实现,可以提供更具体的问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值