資源簡介
本人最近練手做的小項目,在CSDN上也參考了很多代碼,積分花了不少可是大多都沒用上!要么是版本不對勁,要么是完全讀不懂,所以自己上傳了!代碼包括車牌定位,車牌傾斜校正,字符分割。字符的識別部分未做完。

代碼片段和文件信息
#include?
#include?
#include?
#include?
using?namespace??std;
using?namespace?cv;
#?define?PI?3.1415926
#include?“hough_find_line.cpp“
int?verifySizes(Rect?mMat?input);
int?main()
{
Mat?img_gray;
Mat?input=imread(“41.jpg“);
cvtColor(input?img_gray?CV_BGR2GRAY);
blur(img_gray?img_gray?Size(55));?????
//**************************************************第一部分——車牌定位***************************//
//?突出垂直邊緣
Mat?img_sobel;
Sobel(img_gray?img_sobel?CV_8U?1?0?3?1?0?BORDER_DEFAULT);
//imshow(“Sobel“?img_sobel);
//?閾值化處理形態學處理
Mat?img_threshold;
threshold(img_sobel?img_threshold?0?255?CV_THRESH_OTSU+CV_THRESH_BINARY);
////imshow(“Threshold“?img_threshold);
Mat?gauss_diffthreshAgain_diff;
GaussianBlur(img_thresholdgauss_diffSize(99)3.0);//對二值圖像高斯濾波
//imshow(“gauss_diff“gauss_diff);
threshold(gauss_diffthreshAgain_diff29255CV_THRESH_BINARY);//再次閾值化取二值
//imshow(“threshAgain_diff“threshAgain_diff);
Mat?mor_close;
Mat?mor_open;
Mat?element5(88CV_8UScalar(1));
Mat?element?=?getStructuringElement(MORPH_RECT?Size(244)?);
morphologyEx(threshAgain_diff?mor_close?CV_MOP_CLOSE?element);//閉運算
//imshow(“closed“mor_close);
morphologyEx(mor_closemor_openMORPH_OPENelement5);//開運算
//imshow(“open“mor_open);
//?利用findContours函數尋找車牌可能的輪廓
vector?>?contours;
findContours(mor_open
contours //?輪廓的數組
CV_RETR_EXTERNAL //?獲取外輪廓
CV_CHAIN_APPROX_NONE);?//?獲取每個輪廓的每個像素
//?排除非車牌的可能輪廓
vector?>::iterator?itc=?contours.begin();
vector?rects;??
while?(itc!=contours.end())?
{
//?minAreaRect函數計算最小包圍旋轉矩形
Rect?mr=?boundingRect(Mat(*itc));
if(?!verifySizes(mrimg_gray)){
itc=?contours.erase(itc);
}else{
++itc;
rects.push_back(mr);
}
}
//?畫出輪廓
cv::Mat?result;
input.copyTo(result);
cv::drawContours(resultcontours
-1?//?draw?all?contours
cv::Scalar(00255)?//?in?blue
1);?//?with?a?thickness?of?1
//imshow(“resu“result);
//提取出車牌
Mat?imgroi;
vector::iterator?it=rects.begin();
imgroi?=?input(*it);
//imshow(“Plate“imgroi);
//**************************************************第二部分——字符分割***************************//
Mat?imgroi_gray;
cvtColor(imgroiimgroi_grayCV_BGR2GRAY);
//imshow(“imgroi_gray“imgroi_gray);
Mat?imgroi_gray_thre;
threshold(imgroi_grayimgroi_gray_thre?0?255?CV_THRESH_OTSU+CV_THRESH_BINARY);
imshow(“imgroi_gray_thre“imgroi_gray_thre);
erode(imgroi_gray_threimgroi_gray_threcv::Mat());
//****************************傾斜校正
cv::Mat?contours2;??
Canny(imgroi_graycontours2125350);
LineFinder?finder;
finder.setMinVote(70);
finder.setLineLengthAndGap?(10025);??
vector?lines=finder.findLines?(contours2);?
int?n=lines.size();
double?*?d=new?double[n];
int?k=0;
Vec4i?Maxline=finder.findMaxline(linesndk);
Point?pt1(M
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????184566??2015-05-14?10:35??anpr2\anpr2\11.jpg
?????文件?????248517??2015-05-12?21:14??anpr2\anpr2\41.jpg
?????文件???????8827??2015-05-18?15:25??anpr2\anpr2\anpr2.cpp
?????文件???????3269??2015-05-14?16:47??anpr2\anpr2\anpr2.vcxproj
?????文件???????1042??2015-05-14?16:47??anpr2\anpr2\anpr2.vcxproj.filters
?????文件????????143??2015-05-13?22:07??anpr2\anpr2\anpr2.vcxproj.user
?????文件????????500??2015-05-18?13:13??anpr2\anpr2\Debug\anpr2.Build.CppClean.log
?????文件????????381??2015-05-18?13:48??anpr2\anpr2\Debug\anpr2.exe.intermediate.manifest
?????文件?????????70??2015-05-18?13:48??anpr2\anpr2\Debug\anpr2.lastbuildstate
?????文件???????3716??2015-05-18?13:48??anpr2\anpr2\Debug\anpr2.log
?????文件?????555384??2015-05-18?13:48??anpr2\anpr2\Debug\anpr2.obj
?????文件????????707??2015-05-18?13:38??anpr2\anpr2\Debug\anpr2.vcxprojResolveAssemblyReference.cache
?????文件??????????0??2015-05-18?13:13??anpr2\anpr2\Debug\anpr2.write.1.tlog
?????文件???????1230??2015-05-18?13:48??anpr2\anpr2\Debug\cl.command.1.tlog
?????文件??????26260??2015-05-18?13:48??anpr2\anpr2\Debug\CL.read.1.tlog
?????文件???????1074??2015-05-18?13:48??anpr2\anpr2\Debug\CL.write.1.tlog
?????文件??????49906??2015-05-18?13:13??anpr2\anpr2\Debug\hough_find_line.obj
?????文件???????3160??2015-05-18?13:48??anpr2\anpr2\Debug\li
?????文件???????6916??2015-05-18?13:48??anpr2\anpr2\Debug\li
?????文件????????822??2015-05-18?13:48??anpr2\anpr2\Debug\li
?????文件????????462??2015-05-18?13:48??anpr2\anpr2\Debug\mt.command.1.tlog
?????文件????????318??2015-05-18?13:48??anpr2\anpr2\Debug\mt.read.1.tlog
?????文件????????318??2015-05-18?13:48??anpr2\anpr2\Debug\mt.write.1.tlog
?????文件?????461824??2015-05-18?13:48??anpr2\anpr2\Debug\vc100.idb
?????文件?????569344??2015-05-18?13:48??anpr2\anpr2\Debug\vc100.pdb
?????文件???????1984??2015-05-15?11:51??anpr2\anpr2\hough_find_line.cpp
????.......?????????0??2009-08-31?02:32??anpr2\anpr2\line_finder.h
?????文件???11620352??2015-05-18?15:25??anpr2\anpr2.sdf
?????文件????????882??2015-05-13?22:07??anpr2\anpr2.sln
????..A..H.?????14336??2015-05-18?15:25??anpr2\anpr2.suo
............此處省略14個文件信息
評論
共有 條評論