基于OpenCV的车牌识别一整套


这是一整套的车牌定位程序,其汉字由于作者比较懒做字符集的时候只做了。三个省份的:粤,鄂,湘。这个程序公开是为了向ForeverYang2015致敬,当初是他的公开程序才让我开始接触车牌识别。
资源截图
代码片段和文件信息
#include “carID_Detection.h“



void RgbConvToGray(const Mat& inputImageMat & outpuImage)  //g = 0.3R+0.59G+0.11B
{
outpuImage = Mat(inputImage.rows inputImage.cols CV_8UC1);  

for (int i = 0 ;i {
uchar *ptrGray = outpuImage.ptr(i); 
const Vec3b * ptrRgb = inputImage.ptr(i);
for (int j = 0 ;j {
ptrGray[j] = 0.3*ptrRgb[j][2]+0.59*ptrRgb[j][1]+0.11*ptrRgb[j][0];
}
}
}

void posDetect_closeImg(Mat &inputImage  vector  & rects  )   //初步找到候选区域 rects
{

Mat img_canny;
Canny(inputImage img_canny 150 220);
Mat img_threshold;
threshold(img_canny  img_threshold0255  CV_THRESH_OTSU+CV_THRESH_BINARY); //otsu算法自动获得阈值

Mat element = getStructuringElement(MORPH_RECT Size(15 3));  //闭形态学的结构元素
morphologyEx(img_threshold img_thresholdCV_MOP_CLOSEelement);  //形态学处理

//寻找车牌区域的轮廓
vector< vector  > contours;
findContours(img_threshold contoursCV_RETR_EXTERNAL CV_CHAIN_APPROX_NONE);//只检测外轮廓
//对候选的轮廓进行进一步筛选
vector< vector  > ::iterator itc = contours.begin();

while( itc != contours.end())
{
RotatedRect mr = minAreaRect(Mat( *itc )); //返回每个轮廓的最小有界矩形区域
   if(!verifySizes_closeImg(mr))  //判断矩形轮廓是否符合要求
{
itc = contours.erase(itc);
}
else     
{

rects.push_back(mr);
++itc;
}      
}

}


bool verifySizes_closeImg(const RotatedRect & candidate)
{
float error = 0.4;
const float aspect = 44/14; //长宽比
int min = 100*aspect*100; //最小区域
int max = 180*aspect*180;  //最大区域
float rmin = aspect - aspect*error; //考虑误差后的最小长宽比
float rmax = aspect + aspect*error; //考虑误差后的最大长宽比

int area = candidate.size.height * candidate.size.width;
float r = (float)candidate.size.width/(float)candidate.size.height;
if(r <1)
r = 1/r;

if( (area < min || area > max) || (r< rmin || r > rmax)  )
return false;
else
return true;
}

void posDetect(Mat &inputImage  vector  & rects  )   //初步找到候选区域 rects
{
Mat img_sobel;
Sobel(inputImage  img_sobel  CV_8U 10310);

Mat img_threshold;
threshold(img_sobel  img_threshold0255  CV_THRESH_OTSU+CV_THRESH_BINARY); //otsu算法自动获得阈值

Mat element = getStructuringElement(MORPH_RECT Size(15 3));  //闭形态学的结构元素
morphologyEx(img_threshold img_thresholdCV_MOP_CLOSEelement);  

//寻找车牌区域的轮廓
vector< vector  > contours;
findContours(img_threshold contoursCV_RETR_EXTERNAL CV_CHAIN_APPROX_NONE);//只检测外轮廓
//对候选的轮廓进行进一步筛选
vector< vector  > ::iterator itc = contours.begin();

while( itc != contours.end())
{
RotatedRect mr = minAreaRect(Mat( *itc )); //返回每个轮廓的最小有界矩形区域
if(!verifySizes(mr))  //判断矩形轮廓是否符合要求
{
itc = contours.erase(itc);
}
else     
{
rects.push_back(mr);
++itc;
}      
}
}

bool verifySizes(const RotatedRect & candidate)
{
float error = 0.4;
const float aspect = 44/14; //长宽比
int min = 20*aspect*20; //最小区域
in

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     780515  2016-05-05 16:03  CarNumberCarNumberann_xml.xml

     文件      12991  2016-05-07 15:46  CarNumberCarNumbercarID_Detection.cpp

     文件       1842  2016-05-07 15:44  CarNumberCarNumbercarID_Detection.h

     文件       4118  2016-05-05 20:19  CarNumberCarNumberCarNumber.vcxproj

     文件       1308  2016-05-05 20:19  CarNumberCarNumberCarNumber.vcxproj.filters

     文件        143  2016-03-02 22:19  CarNumberCarNumberCarNumber.vcxproj.user

     文件     699173  2016-05-07 14:54  CarNumberCarNumberDebugcarID_Detection.obj

     文件        406  2016-04-30 23:06  CarNumberCarNumberDebugCarNumber.exe.embed.manifest

     文件        472  2016-04-30 23:06  CarNumberCarNumberDebugCarNumber.exe.embed.manifest.res

     文件        381  2016-05-07 14:54  CarNumberCarNumberDebugCarNumber.exe.intermediate.manifest

     文件         77  2016-05-07 14:54  CarNumberCarNumberDebugCarNumber.lastbuildstate

     文件       8291  2016-05-07 14:54  CarNumberCarNumberDebugCarNumber.log

     文件        208  2016-04-30 23:06  CarNumberCarNumberDebugCarNumber_manifest.rc

     文件       3714  2016-05-07 14:54  CarNumberCarNumberDebugcl.command.1.tlog

     文件      80762  2016-05-07 14:54  CarNumberCarNumberDebugCL.read.1.tlog

     文件       5272  2016-05-07 14:54  CarNumberCarNumberDebugCL.write.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink-cvtres.read.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink-cvtres.write.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink.11148-cvtres.read.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink.11148-cvtres.write.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink.11148.read.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink.11148.write.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink.16264-cvtres.read.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink.16264-cvtres.write.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink.16264.read.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink.16264.write.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink.16584-cvtres.read.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink.16584-cvtres.write.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink.16584.read.1.tlog

     文件          2  2016-05-07 14:54  CarNumberCarNumberDebuglink.16584.write.1.tlog

............此处省略2142个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)