Licenseplate Detection Codes Main - CPP
Licenseplate Detection Codes Main - CPP
cpp
#include "Main.h"
#include<opencv2\opencv.hpp>
/////////////////////////////////////////////////////////////////////////////////////////
//////////
//inline
int main (void) {
std::vector<PossiblePlate> vectorOfPossiblePlates =
detectPlatesInScene(imgOriginalScene); // detect plates
vectorOfPossiblePlates = detectCharsInPlates(vectorOfPossiblePlates);
// detect chars in plates
if (vectorOfPossiblePlates.empty()) {
// if no plates were found
std::cout << std::endl << "no license plates were detected" << std::endl;
// inform user no plates were found
}
else { //
else
//
if we get in here vector of possible plates has at leat one plate
//
sort the vector of possible plates in DESCENDING order (most number of chars to least
number of chars)
std::sort(vectorOfPossiblePlates.begin(), vectorOfPossiblePlates.end(),
PossiblePlate::sortDescendingByNumberOfChars);
// suppose the plate with the most recognized chars (the first plate in sorted by
string length descending order) is the actual plate
PossiblePlate licPlate = vectorOfPossiblePlates.front();
if (licPlate.strChars.length() == 0) {
// if no chars were found in the plate
std::cout << std::endl << "no characters were detected" << std::endl <<
std::endl; // show message
return(0);
// and exit program
}
std::cout << std::endl << "license plate read from image = " << licPlate.strChars
<< std::endl; // write license plate text to std out
std::cout << std::endl << "-----------------------------------------" <<
std::endl;
return(0);
}
/////////////////////////////////////////////////////////////////////////////////////////
//////////
void drawRedRectangleAroundPlate(cv::Mat &imgOriginalScene, PossiblePlate &licPlate) {
cv::Point2f p2fRectPoints[4];
/////////////////////////////////////////////////////////////////////////////////////////
//////////
void writeLicensePlateCharsOnImage(cv::Mat &imgOriginalScene, PossiblePlate &licPlate) {
cv::Point ptCenterOfTextArea; // this will be the center of the
area the text will be written to
cv::Point ptLowerLeftTextOrigin; // this will be the bottom left of
the area that the text will be written to
ptCenterOfTextArea.x = (int)licPlate.rrLocationOfPlateInScene.center.x; //
the horizontal location of the text area is the same as the plate