資源簡介
這是一整套的車牌定位程序,其漢字由于作者比較懶做字符集的時候只做了。三個省份的:粵,鄂,湘。這個程序公開是為了向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(17?3));??//閉形態學的結構元素
morphologyEx(img_threshold?img_thresholdCV_MOP_CLOSEelement);??//形態學處理
morphologyEx(img_threshold?img_thresholdMORPH_OPENelement);
//尋找車牌區域的輪廓
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?=?20*aspect*20;?//最小區域
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);
//Sobel(img_sobelimg_sobelCV_8U1310);
Mat?img_threshold;
threshold(img_sobel??img_threshold0255??CV_THRESH_OTSU+CV_THRESH_BINARY);?//otsu算法自動獲得閾值
Mat?element?=?getStructuringElement(MORPH_RECT?Size(17?3));??//閉形態學的結構元素
morphologyEx(img_threshold?img_thresholdCV_MOP_CLOSEelement);??
morphologyEx(img_thresholdimg_thresholdMORPH_OPENelement);
//Sobel(img_thresholdimg_thresholdCV_8U10310);
//morphologyEx(img_threshold?img_thresholdCV_MOP_CLOSEelement);??
//morphologyEx(img_thresholdimg_thresholdMORPH_OPENelement);
namedWindow(“img“CV_WINDOW_NORMAL);
imshow(“img“img_threshold);
//waitKey();
//尋找車牌區域的輪廓
vector?>?contours;
findContours(img_threshold?contoursCV_RETR_EXTERNAL?CV_CHAIN_APPROX_NONE);//只檢測外輪廓
//對候選的輪廓進行進一步篩選
vector
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-07-25?20:37??CarNumber\
?????文件??????125522??2016-06-17?11:39??CarNumber\1.jpg
?????文件??????164788??2016-06-17?11:39??CarNumber\10.jpg
?????文件??????152372??2016-06-17?11:39??CarNumber\11.jpg
?????文件??????171524??2016-06-17?11:39??CarNumber\12.jpg
?????文件??????192436??2016-06-17?11:39??CarNumber\13.jpg
?????文件??????109126??2016-06-17?11:39??CarNumber\14.jpg
?????文件??????293362??2016-06-17?11:39??CarNumber\15.jpg
?????文件??????318958??2016-06-17?11:39??CarNumber\16.jpg
?????文件??????153084??2016-06-17?11:39??CarNumber\17.jpg
?????文件??????345177??2016-06-17?11:39??CarNumber\18.jpg
?????文件??????187703??2016-06-17?11:39??CarNumber\19.jpg
?????文件??????168293??2016-06-17?11:39??CarNumber\2.jpg
?????文件??????197126??2016-06-17?11:39??CarNumber\20.jpg
?????文件??????176264??2016-06-17?11:39??CarNumber\21.jpg
?????文件??????144435??2016-06-17?11:39??CarNumber\22.jpg
?????文件??????135291??2016-06-17?11:39??CarNumber\23.jpg
?????文件??????119776??2016-06-17?11:39??CarNumber\24.jpg
?????文件??????335158??2016-06-17?11:39??CarNumber\25.jpg
?????文件??????180912??2016-06-17?11:39??CarNumber\26.jpg
?????文件??????105402??2016-06-17?11:39??CarNumber\27.jpg
?????文件??????158370??2016-06-17?11:39??CarNumber\28.jpg
?????文件??????202602??2016-06-17?11:39??CarNumber\3.jpg
?????文件??????121013??2016-06-17?11:39??CarNumber\4.jpg
?????文件??????232989??2016-06-17?11:39??CarNumber\5.jpg
?????文件??????154374??2016-06-17?11:39??CarNumber\6.jpg
?????文件??????370419??2016-06-17?11:39??CarNumber\7.jpg
?????文件??????137046??2016-06-17?11:39??CarNumber\8.jpg
?????文件??????200607??2016-06-17?11:39??CarNumber\9.jpg
?????文件??????795336??2017-03-21?15:41??CarNumber\ann_xm
?????文件???????61946??2017-03-21?14:26??CarNumber\ann_xm
............此處省略1949個文件信息
- 上一篇:愛快ap.rar
- 下一篇:Eagle7725攝像頭野火鷹眼7225攝像頭代碼啟動
評論
共有 條評論