ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

HyperLPR车牌识别库代码分析总结(14)

2021-12-25 15:58:01  阅读:176  来源: 互联网

标签:plate HyperLPR 14 25 res image 车牌 图片


2021SC@SDUSC

源代码下载地址:https://gitee.com/zeusees/HyperLPR

源码配置的详情见第一篇分析

 本篇内容将总结之前所分析的三个函数:

一、SimpleRecognizePlateByE2E(self,image)函数

    def SimpleRecognizePlateByE2E(self,image):
        images = self.detectPlateRough(image,image.shape[0],top_bottom_padding_rate=0.1)
        res_set = []
        for j,plate in enumerate(images):
            plate, rect  =plate
            image_rgb,rect_refine = self.finemappingVertical(plate,rect)
            res,confidence = self.recognizeOne(image_rgb)
            res_set.append([res,confidence,rect_refine])
        return res_set

       对导入的车牌文件(也就是图片)进行车牌粗定位,目的是找出图中所有的车牌,这部分是通过delectPlateRough函数实现的。找出所有车牌后,对图中所有车牌进行精定位,也就是沿着这些车牌的轮廓,将车牌裁剪下来,方便接下来对车牌内容进行识别,这项功能是通过finemappingVertical函数实现的。最后要对车牌进行文字识别,通过recognizeOne函数实现。

二、SimpleRecognizePlateByE2E(image)函数

def SimpleRecognizePlateByE2E(image):
    t0 = time.time()
    images = detect.detectPlateRough(image,image.shape[0],top_bottom_padding_rate=0.1)
    res_set = []
    for j,plate in enumerate(images):
        plate, rect, origin_plate  =plate
        plate  =cv2.resize(plate,(136,36*2))
        res,confidence = e2e.recognizeOne(origin_plate)
        print "res",res
 
        t1 = time.time()
        ptype = td.SimplePredict(plate)
        if ptype>0 and ptype<5:
            plate = cv2.bitwise_not(plate)
        image_rgb = fm.findContoursAndDrawBoundingBox(plate)
        image_rgb = fv.finemappingVertical(image_rgb)
        image_rgb = fv.finemappingVertical(image_rgb)
        cache.verticalMappingToFolder(image_rgb)
        res,confidence = e2e.recognizeOne(image_rgb)
        print res,confidence
        res_set.append([[],res,confidence])
 
        if confidence>0.7:
            image = drawRectBox(image, rect, res+" "+str(round(confidence,3)))
    return image,res_set

        该函数主要作用是先用detectPlateRough进行车牌粗定位,识别车牌,获取车牌图片。后对这组图片用resize裁剪,再使用recognizeOne进行初步文字识别,再通过bitwise_not将其图片各像素取“非”。通过findContoursAndDrawBoundingBox函数,在车牌字符没有出现完全的粘连的情况下,进行精定位-确定上下边界,寻找图片的上下界,并将图片转正,剔除噪点。然后再用两次的finemappingVertical识别出文字,剔除没有文字的背景,并返回置信度。先使用verticalMappingToFolder生成图片标签,最后再对该图片用recognizeOne识别文字一次,判断置信度,完成识别操作。

        该函数与第一个函数的区别在于先对图片进行recognizeOne识别,再在finemappingVertical之前使用了findContoursAndDrawBoundingBox(plate)对图片进行寻找上下界和剔除噪点的工作。并在此之后用verticalMappingToFolder生成图片文件,再进行recognizeOne识别字符操作,最后完成识别操作。

三、SimpleRecognizePlate(image)函数

def SimpleRecognizePlate(image):
    t0 = time.time()
    images = detect.detectPlateRough(image,image.shape[0],top_bottom_padding_rate=0.1)
    res_set = []
    for j,plate in enumerate(images):
        plate, rect, origin_plate  =plate
        # plate = cv2.cvtColor(plate, cv2.COLOR_RGB2GRAY)
        plate  =cv2.resize(plate,(136,36*2))
        t1 = time.time()

        ptype = td.SimplePredict(plate)
        if ptype>0 and ptype<5:
            plate = cv2.bitwise_not(plate)

        image_rgb = fm.findContoursAndDrawBoundingBox(plate)

        image_rgb = fv.finemappingVertical(image_rgb)
        cache.verticalMappingToFolder(image_rgb)
        print("e2e:", e2e.recognizeOne(image_rgb))
        image_gray = cv2.cvtColor(image_rgb,cv2.COLOR_RGB2GRAY)
        cv2.imshow("image_gray",image_gray)
        cv2.imwrite("./"+str(j)+".jpg",image_gray)
        print("校正",time.time() - t1,"s")
        t2 = time.time()
        val = segmentation.slidingWindowsEval(image_gray)
        print("分割和识别",time.time() - t2,"s")
        if len(val)==3:
            blocks, res, confidence = val
            if confidence/7>0.7:
                image =  drawRectBox(image,rect,res)
                res_set.append(res)
                for i,block in enumerate(blocks):
                    block_ = cv2.resize(block,(25,25))
                    block_ = cv2.cvtColor(block_,cv2.COLOR_GRAY2BGR)
                    image[j * 25:(j * 25) + 25, i * 25:(i * 25) + 25] = block_
                    if image[j*25:(j*25)+25,i*25:(i*25)+25].shape == block_.shape:
                        pass
            if confidence>0:
                print("车牌:",res,"置信度:",confidence/7)
            else:
                pass
                # print "不确定的车牌:", res, "置信度:", confidence
    print(time.time() - t0,"s")
    return image,res_set

        该函数是主要的运行函数,其分析如下:

        该函数主要作用是先用detectPlateRough进行车牌粗定位,识别车牌,获取车牌图片。后对这组图片用cvtColor将图片变成只有灰色和白色的图片,后用resize裁剪,通过bitwise_not将其图片各像素取“非”。通过findContoursAndDrawBoundingBox函数,在车牌字符没有出现完全的粘连的情况下,进行精定位-确定上下边界,寻找图片的上下界,并将图片转正,剔除噪点。然后再用一次的finemappingVertical识别出文字,剔除没有文字的背景,并返回置信度。先使用verticalMappingToFolder生成图片标签并输出,再对该图片用recognizeOne识别文字一次,得出置信度。之后对处理后的文件再进行校准,使用基于滑动窗口的字符分割与识别的slidingWindowsEval函数,与recognizeOne方法功能类似,但识别出置信度不同。置信度大于0.7时,再用drawRectBox函数打上boundingbox和标签,将对一开始输入进行识别的图片中,框出识别出的车牌显示车牌号码。最后把图片保存为jpg的格式并保存至当前文件夹下。

标签:plate,HyperLPR,14,25,res,image,车牌,图片
来源: https://blog.csdn.net/m0_51150414/article/details/122143516

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有