图像库车牌检测方法

python数字图像处理的包

PIL
Pillow
OpenCV
scikit-image
等等

https://www.cnblogs.com/HL-space/p/10588423.html

import cv2
import sys
import time
import numpy as np
import imgaug as ia
from skimage.transform import radon
from imgaug import augmenters as iaa
import os

filePath = "s/"

for root, dirs, files in os.walk(filePath):
    t1 = time.time()
    print (len(files))#获取图片数量
    j=0
    for q in range(106):
         if files[q].endswith('jpg'):
           j=j+1

           img=files[q]#获取图片名字
           print(img)

           img = cv2.imdecode(np.fromfile(filePath+img, dtype=np.uint8), -1)
           w = img.shape[1]
           img = cv2.copyMakeBorder(img, 0, 0, int(0.03*w), 0, cv2.BORDER_REPLICATE)

           seq = iaa.Sequential([iaa.Multiply((2.2, 2.2), per_channel=1)])
            
           Iy = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
           I= seq.augment_image(Iy)

           h, w = I.shape
           if (w > 240):
               I = cv2.resize(I, (240, int((h / w) * 240)))
           I= I - np.mean(I)  # Demean; make the brightness extend above and below zero
           sinogram = radon(I)
           r = np.array([np.sqrt(np.mean(np.abs(line) ** 2)) for line in sinogram.transpose()])
           rotation = np.argmax(r) #index
           print('Rotation: {:.2f} degrees'.format(90 - rotation))
           degree=90-rotation
           M = cv2.getRotationMatrix2D((w/2, h/2), 90 - rotation, 1)
           t2 = time.time()
           print(t2-t1)
           dst = cv2.warpAffine(img, M, (w, h))
           if (degree < 5 and degree > -5):
               crop = dst[int(0.04 * h):int(0.97 * h), 0:int(0.99 * w)]
           elif(degree<=12 and degree>=-12):
               crop = dst[int(0.18 * h):int(0.82 * h), 0:int(0.99*w)]
           elif (degree >= 30 or degree <= -30):
               crop = dst[int(0.30 * h):int(0.66 * h), 0:int(0.99 * w)]
           elif (degree >= 27 or degree <= -27):
                crop = dst[int(0.28 * h):int(0.70 * h), 0:int(0.99*w)]
           elif (degree >= 25 or degree <= -25):
                crop = dst[int(0.26 * h):int(0.72 * h), 0:int(0.99 * w)]
           else:
               crop = dst[int(0.22 * h):int(0.78 * h), 0:int(0.99*w)]
           
           cv2.imencode('.jpg', crop)[1].tofile("E:/s1/"+files[q])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值