毕业设计 python opencv实现车牌识别 矩形矫正

主要代码参考https://blog.csdn.net/wzh191920/article/details/79589506

GitHub:https://github.com/yinghualuowu

答辩通过了,补完~

用的是仿射变换

def img_Transform(car_contours,oldimg,pic_width,pic_hight):
    car_imgs = []
    for car_rect in car_contours:
        if car_rect[2] > -1 and car_rect[2] < 1:
            angle = 1
            # 对于角度为-1 1之间时,默认为1
        else:
            angle = car_rect[2]
        car_rect = (car_rect[0], (car_rect[1][0] + 5, car_rect[1][1] + 5), angle)
        box = cv2.boxPoints(car_rect)

        heigth_point = right_point = [0, 0]
        left_point = low_point = [pic_width, pic_hight]
        for point in box:
            if left_point[0] > point[0]:
                left_point = point
            if low_point[1] > point[1]:
                low_point = point
            if heigth_point[1] < point[1]:
                heigth_point = point
            if right_point[0] < point[0]:
                right_point = point

        if left_point[1] <= right_point[1]:  # 正角度
            new_right_point = [right_point[0], heigth_point[1]]
            pts2 = np.float32([left_point, heigth_point, new_right_point])  # 字符只是高度需要改变
            pts1 = np.float32([left_point, heigth_point, right_point])
            M = cv2.getAffineTransform(pts1, pts2)
            dst = cv2.warpAffine(oldimg, M, (pic_width, pic_hight))
            point_limit(new_right_point)
            point_limit(heigth_point)
            point_limit(left_point)
            car_img = dst[int(left_point[1]):int(heigth_point[1]), int(left_point[0]):int(new_right_point[0])]
            car_imgs.append(car_img)

        elif left_point[1] > right_point[1]:  # 负角度
            new_left_point = [left_point[0], heigth_point[1]]
            pts2 = np.float32([new_left_point, heigth_point, right_point])  # 字符只是高度需要改变
            pts1 = np.float32([left_point, heigth_point, right_point])
            M = cv2.getAffineTransform(pts1, pts2)
            dst = cv2.warpAffine(oldimg, M, (pic_width, pic_hight))
            point_limit(right_point)
            point_limit(heigth_point)
            point_limit(new_left_point)
            car_img = dst[int(right_point[1]):int(heigth_point[1]), int(new_left_point[0]):int(right_point[0])]
            car_imgs.append(car_img)

    return car_imgs

原文地址:https://www.cnblogs.com/yinghualuowu/p/9185404.html

时间: 2024-08-30 03:30:19

毕业设计 python opencv实现车牌识别 矩形矫正的相关文章

毕业设计 python opencv实现车牌识别 界面

主要代码参考https://blog.csdn.net/wzh191920/article/details/79589506 GitHub:https://github.com/yinghualuowu 答辩通过了,补完~ 这里主要是用两种方法进行定位识别 # -*- coding: utf-8 -*- __author__ = '樱花落舞' import tkinter as tk from tkinter.filedialog import * from tkinter import ttk

毕业设计 python opencv实现车牌识别 颜色判断

主要代码参考https://blog.csdn.net/wzh191920/article/details/79589506 GitHub:https://github.com/yinghualuowu 答辩通过了,补完~ 该部分代码还包括缩小边界 def img_color(card_imgs): colors = [] for card_index, card_img in enumerate(card_imgs): green = yello = blue = black = white

opencv实现车牌识别之字符识别

简介 在前面已经讲了车牌的定位和对车牌字符的分割,这里继续是最后对车牌的识别. 字符识别 主要是用了两张办法,第一个是前面 <opencv实现车牌识别之失败经验> 这一篇中用到过的,opencv自带的getPSNR函数,这里不再对它进行讲解. 另一种方法是将分割出来的字符和模板字符都分割成9宫格形式,对比比较每个块中,像素占的比例来匹配分辨出字符. 具体代码如下: double proCale(Mat& mat1, int width_1, int height_1, int widt

基于opencv的车牌识别系统

前言 学习了很长一段时间了,需要沉淀下,而最好的办法就是做一个东西来应用学习的东西,同时也是一个学习的过程. 概述     OpenCV的全称是:Open Source Computer Vision Library.OpenCV是一个基于(开源)发行的跨平台计算机视觉库,可以运行在Linux.Windows和Mac OS操作系统上.它轻量级而且高效——由一系列 C 函数和少量 C++ 类构成,同时提供了Python.Ruby.MATLAB等语言的接口,实现了图像处理和计算机视觉方面的很多通用算

Python+Keras+TensorFlow车牌识别

这个是我使用的车牌识别开源项目的地址:https://github.com/zeusees/HyperLPR Python 依赖 Anaconda for Python 3.x on Win64 Keras (>2.0.0) Theano(>0.9) or Tensorflow(>1.1.x) Numpy (>1.10) Scipy (0.19.1) OpenCV(>3.0) Scikit-image (0.13.0) PIL 准备工作:安装以下依赖包 pip install

车牌识别--倾斜矫正

在车牌识别系统中, 车牌字符能够正确分割的前提是车牌图像能够水平,以至于水平投影和垂直投影能够正常进行.如果车牌倾斜没有矫正,那么水平投影和垂直投影,甚至铆钉都无法正常处理.所以,当车辆信息中获取车牌的第一步,应该是检查倾斜角度,做倾斜矫正. 倾斜矫正,这里使用的算法: 1.倾斜角度检测: 霍夫变换 关于hough变换,可以参考前面图像处理博文: http://blog.csdn.net/liujia2100/article/details/6989693   直线检测 http://blog.

opencv实现车牌识别之车牌号定位_2

简介 前一篇讲解到了将用蓝色筛选后的图片,再一次灰阶/二值化.现在从这里继续讲解. 矩形检测 因为车牌是一个矩形.所以接着将又一次二值化之后的图片,进行膨胀,之后在进行矩形检测.框选出可能是车牌号的矩形区域. 代码如下: int** car_License_box(Mat& mat1, Mat& mat2, int* number){ Mat threshold_output; vector<vector<Point> > contours; vector<V

opencv实现车牌识别之车牌号定位_1

简介 按照在哪里跌倒就在哪里爬起来的精神,本章继续做车牌号的检测识别.所有步骤分为3步完成:车牌号定位,车牌号字符分割.字符识别. 本章为第一部分:车牌号定位. 效果演示 正式开始讲解之前,先看下车牌号定位出来的效果演示.注:本文所有图片均来源于网络. 如图所示,定位到车牌号之后,将车牌号用黄色框选起来,同时将该车牌复制为新图片显示出来. 代码及实现原理讲解 图像灰阶/二值化 首先也是常用的操作,将图像灰阶化,然后从像素值为255一侧开始,以累积像素占总像素5%的的地方作为二值化的阀值,进而获得

opencv实现车牌识别之字符分割

简介 在前一篇中,我们已经定位出来了在图片中车牌号的位置,并且将车牌号图片复制成了新图片,并显示出来,本章在这些被截取出来的图片上继续处理. 截取出来的新图片如下: 图像灰阶/二值化 首先也是选择将图像进行灰阶,然后采用以255一遍开始,取占了总pixel为5%的地方作为阀值,进行二值化. 代码如下: #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <math.h