车牌识别之一:车牌定位【实践篇】

(转) 学习OpenCV——车牌检测(定位) 原文:http://blog.csdn.net/sangni007/article/details/7444470 这两天在做关于车牌识别的实验,用了几种方式: 1.车牌颜色分布(HSV空间,YCrCb空间的没有颜色分布图谱,无法实验);利用HSV的H通道,效果一般,受环境影响大。 [cpp] view plaincopyprint? # 阅读详情

在上一篇文章提到车牌定位,是利用opencv sample里面的一个例子,觉得理论上可行,但没有动手操作过。今天有空,修改了一下代码,试了几个图片,发现效果还好。特贴出代码,和各位opencv学习者交流,同时希望有高手指点指点。O(∩_∩)O

废话少说,代码如下:

 

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//车牌定位
//modified by sing
//2010-10-14

//
// The full "Square Detector" program.
// It loads several images subsequentally and tries to find squares in
// each image
//
#ifdef _CH_
#pragma package <opencv>
#endif

#define CV_NO_BACKWARD_COMPATIBILITY

#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <math.h>
#include <string.h>

int thresh = 50;
IplImage* img = 0;
IplImage* img0 = 0;
CvMemStorage* storage = 0;
const char* wndname = "Square Detection Demo";

// helper function:
// finds a cosine of angle between vectors
// from pt0->pt1 and from pt0->pt2
double angle( CvPoint* pt1, CvPoint* pt2, CvPoint* pt0 )
{
    double dx1 = pt1->x - pt0->x;
    double dy1 = pt1->y - pt0->y;
    double dx2 = pt2->x - pt0->x;
    double dy2 = pt2->y - pt0->y;
    return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);
}

// returns sequence of squares detected on the image.
// the sequence is stored in the specified memory storage
CvSeq* findSquares4( IplImage* img, CvMemStorage* storage )
{
    CvSeq* contours;
    int i, c, l, N = 1;
    CvSize sz = cvSize( img->width & -2, img->height & -2 );    //保证最后一位是偶数,by sing 2010-10-11
    IplImage* timg = cvCloneImage( img ); // make a copy of input image
    IplImage* gray = cvCreateImage( sz, 8, 1 );
    IplImage* pyr = cvCreateImage( cvSize(sz.width/2, sz.height/2), 8, 3 );
    IplImage* tgray;
    CvSeq* result;
    double s, t;
    // create empty sequence that will contain points -
    // 4 points per square (the square's vertices)
    CvSeq* squares = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvPoint), storage );

    // select the maximum ROI in the image
    // with the width and height divisible by 2
    cvSetImageROI( timg, cvRect( 0, 0, sz.width, sz.height ));

    // down-scale and upscale the image to filter out the noise
    cvPyrDown( timg, pyr, 7 );
    cvPyrUp( pyr, timg, 7 );
    tgray = cvCreateImage( sz, 8, 1 );

    // find squares in every color plane of the image
    for( c = 0; c < 3; c++ )
    {
        // extract the c-th color plane
        cvSetImageCOI( timg, c+1 );

        cvCopy( timg, tgray, 0 );

        // try several threshold levels
        //for( l = 0; l < N; l++ )
        {
            // hack: use Canny instead of zero threshold level.
            // Canny helps to catch squares with gradient shading
            //if( l == 0 )
            //{
            //    // apply Canny. Take the upper threshold from slider
            //    // and set the lower to 0 (which forces edges merging)
            //    cvCanny( tgray, gray, 0, thresh, 5 );
            //    // dilate canny output to remove potential
            //    // holes between edge segments
            //    cvDilate( gray, gray, 0, 1 );
            //}
            //else
            {
                // apply threshold if l!=0:
                //     tgray(x,y) = gray(x,y) < (l+1)*255/N ? 255 : 0
                cvThreshold( tgray, gray, /*(l+1)*255/N*/100, 255, CV_THRESH_BINARY );
            }

            // find contours and store them all as a list
            cvFindContours( gray, storage, &contours, sizeof(CvContour),
                CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );

            // test each contour
            while( contours )
            {
                // approximate contour with accuracy proportional
                // to the contour perimeter
                result = cvApproxPoly( contours, sizeof(CvContour), storage,
                    CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.02, 0 );
                // square contours should have 4 vertices after approximation
                // relatively large area (to filter out noisy contours)
                // and be convex.
                // Note: absolute value of an area is used because
                // area may be positive or negative - in accordance with the
                // contour orientation
                if( result->total == 4 &&
                    cvContourArea(result,CV_WHOLE_SEQ,0) > 1000 &&
                    cvContourArea(result,CV_WHOLE_SEQ,0) < (sz.width * sz.height / 4) && 
                    cvCheckContourConvexity(result) )
                {
                    s = 0;

                    for( i = 0; i < 5; i++ )
                    {
                        // find minimum angle between joint
                        // edges (maximum of cosine)
                        if( i >= 2 )
                        {
                            t = fabs(angle(
                                (CvPoint*)cvGetSeqElem( result, i ),
                                (CvPoint*)cvGetSeqElem( result, i-2 ),
                                (CvPoint*)cvGetSeqElem( result, i-1 )));
                            s = s > t ? s : t;
                        }
                    }

                    // if cosines of all angles are small
                    // (all angles are ~90 degree) then write quandrange
                    // vertices to resultant sequence
                    if( s < 0.3 )
                        for( i = 0; i < 4; i++ )
                            cvSeqPush( squares,
                            (CvPoint*)cvGetSeqElem( result, i ));
                }

                // take the next contour
                contours = contours->h_next;
            }
        }
    }

    // release all the temporary images
    cvReleaseImage( &gray );
    cvReleaseImage( &pyr );
    cvReleaseImage( &tgray );
    cvReleaseImage( &timg );

    return squares;
}

//获取最大矩形区域 write by sing 2010-10-14
CvRect GetBoundingRect(CvPoint* points, int count = 4)
{
    unsigned int minX = -1, minY = -1;
    unsigned int maxX = 0, maxY = 0;

    for (int i = 0; i < count; i++) {
        if (minX > points[i].x) {
            minX = points[i].x;
        }
        if (minY > points[i].y) {
            minY = points[i].y;
        }
        if (maxX < points[i].x) {
            maxX = points[i].x;
        }
        if (maxY < points[i].y) {
            maxY = points[i].y;
        }
    }

    CvRect rc = cvRect(minX, minY, maxX - minX, maxY - minY);

    return rc;
}


// the function draws all the squares in the image
void drawSquares( IplImage* img, CvSeq* squares )
{
    CvSeqReader reader;
    IplImage* cpy = cvCloneImage( img );
    int i;

    // initialize reader of the sequence
    cvStartReadSeq( squares, &reader, 0 );

    // read 4 sequence elements at a time (all vertices of a square)
    for( i = 0; i < squares->total; i += 4 )
    {
        CvPoint pt[4], *rect = pt;
        int count = 4;

        // read 4 vertices
        CV_READ_SEQ_ELEM( pt[0], reader );
        CV_READ_SEQ_ELEM( pt[1], reader );
        CV_READ_SEQ_ELEM( pt[2], reader );
        CV_READ_SEQ_ELEM( pt[3], reader );

        // draw the square as a closed polyline
        cvPolyLine( cpy, &rect, &count, 1, 1, CV_RGB(0,255,0), 1, CV_AA, 0 );

        //截取图像并判断是否为车牌
        CvRect rc = GetBoundingRect(pt, count);
        //printf("[%d, %d, %d, %d]/n", rc.x, rc.y, rc.width, rc.height);
        IplImage* img2 = cvCreateImage(cvSize(rc.width, rc.height), IPL_DEPTH_8U, 3);
        cvZero(img2);
        cvSetImageROI(img, rc);
        cvCopyImage(img, img2);
        cvResetImageROI(img);
       
        cvNamedWindow("tmp", CV_WINDOW_AUTOSIZE);
        cvShowImage("tmp", img2);
        cvReleaseImage(&img2);
        cvWaitKey(0);
    }

    // show the resultant image
    cvShowImage( wndname, cpy );
    cvReleaseImage( &cpy );
}


char* names[] = {
    "1.bmp", "2.bmp", "3.bmp",
    "4.bmp", "5.bmp", 0
};

int main(int argc, char** argv)
{
    int i, c;
    // create memory storage that will contain all the dynamic data
    storage = cvCreateMemStorage(0);

    for( i = 0; names[i] != 0; i++ )
    {
        // load i-th image
        img0 = cvLoadImage( names[i], 1 );
        if( !img0 )
        {
            printf("Couldn't load %s/n", names[i] );
            continue;
        }
        img = cvCloneImage( img0 );

        // create window and a trackbar (slider) with parent "image" and set callback
        // (the slider regulates upper threshold, passed to Canny edge detector)
        cvNamedWindow( wndname, 1 );

        // find and draw the squares
        drawSquares( img, findSquares4( img, storage ) );

        // wait for key.
        // Also the function cvWaitKey takes care of event processing
        c = cvWaitKey(0);
        // release both images
        cvReleaseImage( &img );
        cvReleaseImage( &img0 );
        // clear memory storage - reset free space position
        cvClearMemStorage( storage );
        if( (char)c == 27 )
            break;
    }

    cvDestroyWindow( wndname );

    return 0;
}

 

 

汽车车牌识别系统实现(二)--车牌定位+代码实现 汽车车牌识别系统实现(二)-- 车牌定位 前言 本人大四计算机视觉处理方面菜鸟一枚,因个人兴趣和毕设的缘故,故而想学习计算机视觉方面的内容,有不正确的地方还等各位大神批评指正。 图像预处理 照相机获取到汽车车牌图像时,绝大多数情况下,图像里只存在一个车牌的情况是不太现实的,一幅图像里存在建筑物、树、其它汽车等等是很正常的;而且绝大多数都会存在噪声点,这种情况下就会对车牌定位和识别造成极大程度的干扰... 阅读详情

相关推荐

车牌识别算法 基于yolov5的车牌检测+crnn中文车牌识别 支持12种中文车牌识别

最全车牌识别算法,支持12种中文车牌类型了。 基于yolov5的车牌检测 crnn车牌识别 关键点定位车牌 1.单行蓝牌 2.单行黄牌 3.新能源车牌 4.白色警用车牌 5 教练车牌 6 武警车牌 7 双层黄牌 8 双层武警 9 使馆车牌 10 港澳牌车 11 双层农用车牌12 民航车牌

we00912345的博客 3万+

车牌识别(一)——车牌定位(附详细代码及注释)

车牌识别分三步:车牌定位,车牌字符分割,车牌字符识别。 本篇就车牌定位进行讲述。车牌定位顾名思义——找出车牌的位置。如何实现,又分三步:图像预处理,数学形态学粗定位,长宽比例精确定位。 首先,对图像预处理: 彩色图像转灰度图 高斯滤波,中值滤波 边缘化检测 二值化操作 #-*- coding: utf-8 -*- import cv2 import numpy as np def Proc...

lixiaoyu101的博客 2万+

基于Matlab的车牌识别

基于Matlab的车牌识别 摘要:车牌识别技术是智能交通系统的重要组成部分,在近年来得到了很大的发展。本文从预处理、边缘检测、车牌定位、字符分割、字符识别五个方面,具体介绍了车牌自动识别的原理。并用MATLAB软件编程来实现每一个部分,最后识别出汽车车牌。 一、设计原理 车辆车牌识别系统的基本工作原理为:将摄像头拍摄到的包含车辆车牌的图像通过视频卡输入到计算机中进行预处理,再由检索模块对...

m0_59833680的博客 9338

实战:车牌识别之车牌定位

点击上方“小白学视觉”,选择加"星标"或“置顶”重磅干货,第一时间送达 本文转自|3D视觉工坊从本节起,我们开始尝试做一下车牌识别中的算法部分。从上一节的基本框架图中,可...

小白学视觉 5888

图像车牌识别(车牌定位与分割部分)

图像车牌识别(车牌定位与分割部分)图像车牌识别关键就是要从图像中准确地定位出车牌的位置,并将车牌部分的图像分割出来。 本文设计了一个简易的车牌识别识别系统,现介绍其车牌定位和分割部分。 在设计中我采用了颜色特征和形态特征相结合的方法对车牌进行定位。车牌区域有很丰富的特征信息,如颜色,不同性质的车牌会有不同的颜色,大多数普通的车牌就是字符为白色,背景为蓝色。<1>HSV颜色模型 HSV是根据颜色

紫电青霜 3万+

HyperLPR车牌识别技术算法之车牌精定位

关于HyperLPRHyperLPR是一个使用深度学习针对对中文车牌识别的实现,与较为流行的开源的EasyPR相比,它的检测速度和鲁棒性和多场景的适应性都要好于目前开源的EasyPR,HyperLPR可以识别多种中文车牌包括白牌,新能源车牌,使馆车牌,教练车牌,武警车牌等。 Github地址:https://github.com/zeusees/HyperLPR车牌的精定位我们在训练完casca

Relocy的专栏 2万+

opencv 检测直线、线段、圆、矩形

转自:http://blog.csdn.net/byxdaz/archive/2009/12/01/4912136.aspx   检测直线:cvHoughLines,cvHoughLines2 检测圆:cvHoughCircles 检测矩形:opencv中没有对应的函数,

网络资源是无限的 2万+

车牌识别:HyperLPR车牌识别代码解析

首先声明,这只是本人自己对HyperLPR代码的看法解析可能会有错还请多多谅解。 先贴上HyperLPR源码的链接HyperLPR 其中最有用的其实就是HyperLPRLite.py这个代码文件,原来Github上的使用教程可能有点老了不太适用,这边附上一个简单的demo使用,创建一个新的文件夹然后把HyperLPRLite.py放进文件夹,再在新文件夹里面创建一个demo.py文件,如下(记得要...

qq_43711697的博客 7648

基于matlab的蓝色车牌识别(车牌定位)

目录 一 处理流程 二 结果展示 三 核心要点解读 四 matlab代码实现 整套方案还包括以下博客: (1)基于matlab的蓝色车牌识别(绪论) (2)基于matlab的蓝色车牌识别(车牌定位) (3)基于matlab的蓝色车牌识别(车牌倾斜矫正) (4)基于matlab的蓝色车牌识别(车牌字符分割) (5)基于matlab的蓝色车牌识别(车牌字符识别) 转载请注明出处,...

Joseph__Lagrange的博客 2万+

【老生谈算法】基于matlab的车牌识别算法详解及程序源码——车牌识别算法

基于matlab的车牌识别系统设计与算法原理 大家好,今天给大家介绍基于matlab的车牌识别系统设计与原理。 车牌识别系统(License Plate Recognition ,简称LPR)是智能交通系统(ITS)的核心组成部分,在现代交通管理系统中发挥着举足轻重的作用。本项目运用神经网络算法从车牌图像预处理、车牌定位、车牌字符分割和车牌字符识别这几个方面对车牌识别技术进行研究,运用MATLAB仿真,实现对车牌识别系统的设计。 文章目录: 基于matlab的车牌识别系统设计与算法原理1、项目简介2、难度

m0_53407570的博客 8721

HyperLPR车牌识别技术算法之车牌粗定位与训练

关于HyperLPRHyperLPR是一个使用深度学习针对对中文车牌识别的实现,与较为流行的开源的EasyPR相比,它的检测速度和鲁棒性和多场景的适应性都要好于目前开源的EasyPR,HyperLPR可以识别多种中文车牌包括白牌,新能源车牌,使馆车牌,教练车牌,武警车牌等。 Github地址:https://github.com/zeusees/HyperLPR前言车牌识别是使用OCR来识别车牌

Relocy的专栏 3万+

车牌定位 绝对能用 可以识别一般图片

定位 分割 二值化 C语言 复杂背景下 可能出错 所以要求高的不要下载

C++实现车牌自动识别系统全解析

车牌自动识别系统广泛应用于交通管理、停车场自动化和城市交通监控等领域。它利用图像处理和模式识别技术,自动从车辆图片中提取车牌信息,实现了对车辆的快速识别和信息管理。

weixin_30218749的博客 907

车牌检测+车牌定位完整程序

车牌定位完整程序,可直接运行,在此基础上还可做识别。

车牌识别系统从车牌定位、字符分割到车牌识别效果不错的C++源代码

本项目是我用基于Opencv和C++实现的一整套车牌识别系统从定位、分割到字符识别的源代码,可直接运行使用,效果还不错。

车牌识别之车牌定位

vs2010+opencv,车牌识别共分三个部分,车牌定位,字符分割,字符识别,分三个部分上传,都是调试好的代码,里面配有调试的图片,字符识别用的是bp,svm没有找到相关的代码,如何识别多类的图像没有试验过。

基于车牌形状和颜色的车牌定位

车牌识别学习 前言:近年来,人工智能的研究不断深入,智慧城市,智慧交通也引起了大家的关注,车牌识别作为智慧交通的重要一环,被广泛应用在:停车场管理,违章处理,高速收费等领域。 同时也随着新能源汽车的不断增多,原来识别普通汽车7字符车牌的车牌识别系统需要增加识别新能源汽车8字符车牌的功能。车牌识别主要分为四个步骤:车牌定位,车牌矫正,字符分割和字符识别。 车牌定位:在一张含有车牌的图片中找到车牌区域。主要由三个方向的方法: 一、基于特征的算法,如基于颜色特征和边缘特征的算法,基于字符边缘的算法,就是找到内部

selinaliujunlan的博客 1万+

车牌定位与识别

分别采用vc++2008以及opencv中的函数实现对车牌字符的定位,分割和识别。

上一篇: 车牌识别及验证码识别的一般思路
下一篇: 关于pkg文件的一些高级选项
sing_sing
博客等级 码龄20年 209粉丝 66原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址