Recognition of the car and finding its plate is popular theme for school projects and there are also many commercial systems. This project shows how you can recognize cars and its plate from video record or live stream. After a little modification it can by used to improve some parking systems. Idea of this algorithm is absolute different between frames and lot of testing.
Functions used: medianBlur, cvtColor, adaptiveThreshold, dilate, findContours
Input
The process
- Customizing the size of video footage
- Convert image to gray scale and blur it
medianBlur(mainPicture,temp1,15); cvtColor(temp1,temp1, CV_BGR2GRAY);
- Start making absolute different between every 4 frames
- Threshold picture with number of thresh is 20 and number of maxval is 255
adaptiveThreshold(temp1, temp1, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY_INV, 35, 5);
- Make 25 iterations of dilation
dilate(output,output,Mat(),Point(-1,-1), 25,0);
- Find contures from actual picture and take the area of the biggest conture
findContours( picture.clone(), contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
- Now you have color picture of whole car and the next step is to find a car light. Plate is somewhere between car lights.
- Another conversion to gray scale, erosion, dilation and blur
- Now threshold picture with thresh number 220 and maxval number 255
- Split picture to right part and left part
- Find biggest conture for both sides of the picture
- Make rectangle with both contures in it and slightly wides
Sample
Result
// oznacenie praveho a laveho svetla polylines(tempCar, areaR, true,Scalar(0,255,0), 3, CV_AA); polylines(tempCar, areaL, true,Scalar(255,0,0), 3, CV_AA); //najdenie miesta kde by sa mala nachadzat SPZ if(!areaL.empty() && !areaR.empty() ){ //if( contourArea(Mat(areaL)) - contourArea(Mat(areaR)) < 100 ) { for(int i = 0; i < areaL.size(); i++){ areaR.push_back(areaL[i]); } Rect rectR = boundingRect(areaR); if(rectR.width < 285 && rectR.width > 155 && rectR.height > 4 && rectR.height < 85){ rectR.height = rectR.height + 30; rectangle(tempCar, rectR, CV_RGB(255,0,0)); } }