資源簡介
這是一整套的車牌定位程序,其漢字由于作者比較懶做字符集的時候只做了。三個省份的:粵,鄂,湘。這個程序公開是為了向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?>?contours;
findContours(img_threshold?contoursCV_RETR_EXTERNAL?CV_CHAIN_APPROX_NONE);//只檢測外輪廓
//對候選的輪廓進行進一步篩選
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??max)?||?(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?>?contours;
findContours(img_threshold?contoursCV_RETR_EXTERNAL?CV_CHAIN_APPROX_NONE);//只檢測外輪廓
//對候選的輪廓進行進一步篩選
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??CarNumber\CarNumber\ann_xm
?????文件??????12991??2016-05-07?15:46??CarNumber\CarNumber\carID_Detection.cpp
?????文件???????1842??2016-05-07?15:44??CarNumber\CarNumber\carID_Detection.h
?????文件???????4118??2016-05-05?20:19??CarNumber\CarNumber\CarNumber.vcxproj
?????文件???????1308??2016-05-05?20:19??CarNumber\CarNumber\CarNumber.vcxproj.filters
?????文件????????143??2016-03-02?22:19??CarNumber\CarNumber\CarNumber.vcxproj.user
?????文件?????699173??2016-05-07?14:54??CarNumber\CarNumber\Debug\carID_Detection.obj
?????文件????????406??2016-04-30?23:06??CarNumber\CarNumber\Debug\CarNumber.exe.em
?????文件????????472??2016-04-30?23:06??CarNumber\CarNumber\Debug\CarNumber.exe.em
?????文件????????381??2016-05-07?14:54??CarNumber\CarNumber\Debug\CarNumber.exe.intermediate.manifest
?????文件?????????77??2016-05-07?14:54??CarNumber\CarNumber\Debug\CarNumber.lastbuildstate
?????文件???????8291??2016-05-07?14:54??CarNumber\CarNumber\Debug\CarNumber.log
?????文件????????208??2016-04-30?23:06??CarNumber\CarNumber\Debug\CarNumber_manifest.rc
?????文件???????3714??2016-05-07?14:54??CarNumber\CarNumber\Debug\cl.command.1.tlog
?????文件??????80762??2016-05-07?14:54??CarNumber\CarNumber\Debug\CL.read.1.tlog
?????文件???????5272??2016-05-07?14:54??CarNumber\CarNumber\Debug\CL.write.1.tlog
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
?????文件??????????2??2016-05-07?14:54??CarNumber\CarNumber\Debug\li
............此處省略2142個文件信息
評論
共有 條評論