opencv之车牌检测(初)

来源:互联网 发布:淘宝信用贷款和网商贷 编辑:程序博客网 时间:2024/06/06 19:54

1.we get the classifier of plates with the way of haar and adaboost too. we can detect  the front of the plate or a certain slope plate ,At the same time just can distinguish between blue and white plate。

#include "stdafx.h"#include <iostream>#include "opencv2/opencv.hpp"using namespace cv;using namespace std;int i;void display_number(vector<Rect>plates,Mat&img){cout<<"检测到"<<i<<"个车牌"<<endl;for(int j=0;j<i;j++){    if (j==0){ Rect roi = Rect(plates[0]); Mat roiImg = img(roi);  imshow("roi_0", roiImg);cvMoveWindow("roi_0",0,0);}        if (j==1){ Rect roi = Rect(plates[1]); Mat roiImg = img(roi);  imshow("roi_1", roiImg);cvMoveWindow("roi_1",0,80);}if (j==2){ Rect roi = Rect(plates[0]); Mat roiImg = img(roi);  imshow("roi_2", roiImg);cvMoveWindow("roi_2",0,160);}if (j==3){ Rect roi = Rect(plates[3]); Mat roiImg = img(roi);  imshow("roi_3", roiImg);cvMoveWindow("roi_3",0,240);}if (j==4){ Rect roi = Rect(plates[4]); Mat roiImg = img(roi);  imshow("roi_4", roiImg);cvMoveWindow("roi_4",0,320);}if (j==5){ Rect roi = Rect(plates[5]); Mat roiImg = img(roi);  imshow("roi_5", roiImg);cvMoveWindow("roi_5",0,400);}if (j==6){ Rect roi = Rect(plates[6]); Mat roiImg = img(roi);  imshow("roi_6", roiImg);cvMoveWindow("roi_6",0,480);}if (j==7){ Rect roi = Rect(plates[7]); Mat roiImg = img(roi);  imshow("roi_7", roiImg);cvMoveWindow("roi_7",0,560);}}   }int main(){CascadeClassifier classifier("D://haar_xml//chepaihao//cascade.xml"); Mat img = imread("D://vvoo//chepai3.jpg");    //读取照片vector<Rect> plates;    //代表车牌区域(这里就是58×18)classifier.detectMultiScale(img, plates,1.1, 3, 0);for( i =0; i < plates.size(); i++)   { /*cout<<"plate.x="<<plates[i].x<<endl<<"plate.x="<<plates[i].y<<endl;cout<<"plate.width="<<plates[i].width<<endl<<"plate.height="<<plates[i].height<<endl;*//*rectangle(img, Point(plates[i].x-plates[i].width*0.1,plates[i].y-plates[i].height*0.1),Point(plates[i].x+plates[i].width*1.1,plates[i].y+plates[i].height*1.1) ,Scalar(255, 0, 255), 2);*/rectangle(img, plates[i], Scalar(255, 0,255), 2);}display_number(plates,img);Mat ResizeImage;Size outSize;outSize.width=img.cols*0.25;outSize.height=img.rows*0.25;resize(img,ResizeImage,outSize,0,0,INTER_LINEAR);imshow("plates", ResizeImage);waitKey(0);return 0;}



As can be seen from the figure below, there is some error in the detection  of this classifier.

2.let's appreciate the actual result of plate detection.



I don't understand why  the same plates number is detected two times,the result of detector is better if the pixels of image is more!  


1.http://lib.csdn.net/article/45/57492?knId=1221

原创粉丝点击