mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 18:32:45 +08:00
Moved cleanupColors function over to the platelines class
This commit is contained in:
@@ -47,9 +47,6 @@ void LicensePlateCandidate::recognize()
|
|||||||
Mat plate_bgr = Mat(frame, expandedRegion);
|
Mat plate_bgr = Mat(frame, expandedRegion);
|
||||||
resize(plate_bgr, plate_bgr, Size(config->templateWidthPx, config->templateHeightPx));
|
resize(plate_bgr, plate_bgr, Size(config->templateWidthPx, config->templateHeightPx));
|
||||||
|
|
||||||
Mat plate_bgr_cleaned = Mat(plate_bgr.size(), plate_bgr.type());
|
|
||||||
this->cleanupColors(plate_bgr, plate_bgr_cleaned);
|
|
||||||
|
|
||||||
CharacterRegion charRegion(plate_bgr, config);
|
CharacterRegion charRegion(plate_bgr, config);
|
||||||
|
|
||||||
if (charRegion.confidence > 10)
|
if (charRegion.confidence > 10)
|
||||||
@@ -58,7 +55,7 @@ void LicensePlateCandidate::recognize()
|
|||||||
//Mat boogedy = charRegion.getPlateMask();
|
//Mat boogedy = charRegion.getPlateMask();
|
||||||
|
|
||||||
plateLines.processImage(charRegion.getPlateMask(), &charRegion, 1.10);
|
plateLines.processImage(charRegion.getPlateMask(), &charRegion, 1.10);
|
||||||
plateLines.processImage(plate_bgr_cleaned, &charRegion, 0.9);
|
plateLines.processImage(plate_bgr, &charRegion, 0.9);
|
||||||
|
|
||||||
PlateCorners cornerFinder(plate_bgr, &plateLines, &charRegion, config);
|
PlateCorners cornerFinder(plate_bgr, &plateLines, &charRegion, config);
|
||||||
vector<Point> smallPlateCorners = cornerFinder.findPlateCorners();
|
vector<Point> smallPlateCorners = cornerFinder.findPlateCorners();
|
||||||
@@ -139,40 +136,3 @@ Mat LicensePlateCandidate::deSkewPlate(Mat inputImage, vector<Point2f> corners)
|
|||||||
return deskewed;
|
return deskewed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LicensePlateCandidate::cleanupColors(Mat inputImage, Mat outputImage)
|
|
||||||
{
|
|
||||||
if (this->config->debugGeneral)
|
|
||||||
cout << "LicensePlate::cleanupColors" << endl;
|
|
||||||
|
|
||||||
//Mat normalized(inputImage.size(), inputImage.type());
|
|
||||||
|
|
||||||
Mat intermediate(inputImage.size(), inputImage.type());
|
|
||||||
|
|
||||||
normalize(inputImage, intermediate, 0, 255, CV_MINMAX );
|
|
||||||
|
|
||||||
// Equalize intensity:
|
|
||||||
if(intermediate.channels() >= 3)
|
|
||||||
{
|
|
||||||
Mat ycrcb;
|
|
||||||
|
|
||||||
cvtColor(intermediate,ycrcb,CV_BGR2YCrCb);
|
|
||||||
|
|
||||||
vector<Mat> channels;
|
|
||||||
split(ycrcb,channels);
|
|
||||||
|
|
||||||
equalizeHist(channels[0], channels[0]);
|
|
||||||
|
|
||||||
merge(channels,ycrcb);
|
|
||||||
|
|
||||||
cvtColor(ycrcb,intermediate,CV_YCrCb2BGR);
|
|
||||||
|
|
||||||
//ycrcb.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
bilateralFilter(intermediate, outputImage, 3, 25, 35);
|
|
||||||
|
|
||||||
if (this->config->debugGeneral)
|
|
||||||
{
|
|
||||||
displayImage(config, "After cleanup", outputImage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -64,7 +64,6 @@ class LicensePlateCandidate
|
|||||||
Mat frame;
|
Mat frame;
|
||||||
Rect plateRegion;
|
Rect plateRegion;
|
||||||
|
|
||||||
void cleanupColors(Mat inputImage, Mat outputImage);
|
|
||||||
Mat filterByCharacterHue(vector<vector<Point> > charRegionContours);
|
Mat filterByCharacterHue(vector<vector<Point> > charRegionContours);
|
||||||
vector<Point> findPlateCorners(Mat inputImage, PlateLines plateLines, CharacterRegion charRegion); // top-left, top-right, bottom-right, bottom-left
|
vector<Point> findPlateCorners(Mat inputImage, PlateLines plateLines, CharacterRegion charRegion); // top-left, top-right, bottom-right, bottom-left
|
||||||
|
|
||||||
|
@@ -40,9 +40,20 @@ void PlateLines::processImage(Mat inputImage, CharacterRegion* charRegion, float
|
|||||||
timespec startTime;
|
timespec startTime;
|
||||||
getTime(&startTime);
|
getTime(&startTime);
|
||||||
|
|
||||||
|
// Copy the input image over to the "smoothed" image as grayscale
|
||||||
|
Mat smoothed;
|
||||||
|
cvtColor(inputImage, smoothed, CV_BGR2GRAY);
|
||||||
|
|
||||||
|
drawAndWait(&inputImage);
|
||||||
|
// Ignore input images that are pure white or pure black
|
||||||
|
Scalar avgPixelIntensity = mean(smoothed);
|
||||||
|
if (avgPixelIntensity[0] == 255)
|
||||||
|
return;
|
||||||
|
else if (avgPixelIntensity[0] == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
drawAndWait(&smoothed);
|
||||||
|
|
||||||
Mat smoothed(inputImage.size(), inputImage.type());
|
|
||||||
inputImage.copyTo(smoothed);
|
|
||||||
int morph_elem = 2;
|
int morph_elem = 2;
|
||||||
int morph_size = 2;
|
int morph_size = 2;
|
||||||
Mat element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );
|
Mat element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );
|
||||||
@@ -225,6 +236,44 @@ vector<LineSegment> PlateLines::getLines(Mat edges, bool vertical)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void PlateLines::cleanupColors(Mat inputImage, Mat outputImage)
|
||||||
|
{
|
||||||
|
if (this->config->debugGeneral)
|
||||||
|
cout << "LicensePlate::cleanupColors" << endl;
|
||||||
|
|
||||||
|
//Mat normalized(inputImage.size(), inputImage.type());
|
||||||
|
|
||||||
|
Mat intermediate(inputImage.size(), inputImage.type());
|
||||||
|
|
||||||
|
normalize(inputImage, intermediate, 0, 255, CV_MINMAX );
|
||||||
|
|
||||||
|
// Equalize intensity:
|
||||||
|
if(intermediate.channels() >= 3)
|
||||||
|
{
|
||||||
|
Mat ycrcb;
|
||||||
|
|
||||||
|
cvtColor(intermediate,ycrcb,CV_BGR2YCrCb);
|
||||||
|
|
||||||
|
vector<Mat> channels;
|
||||||
|
split(ycrcb,channels);
|
||||||
|
|
||||||
|
equalizeHist(channels[0], channels[0]);
|
||||||
|
|
||||||
|
merge(channels,ycrcb);
|
||||||
|
|
||||||
|
cvtColor(ycrcb,intermediate,CV_YCrCb2BGR);
|
||||||
|
|
||||||
|
//ycrcb.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
bilateralFilter(intermediate, outputImage, 3, 25, 35);
|
||||||
|
|
||||||
|
if (this->config->debugGeneral)
|
||||||
|
{
|
||||||
|
displayImage(config, "After cleanup", outputImage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vector<LineSegment> PlateLines::getLines(Mat edges, float sensitivityMultiplier, bool vertical)
|
vector<LineSegment> PlateLines::getLines(Mat edges, float sensitivityMultiplier, bool vertical)
|
||||||
{
|
{
|
||||||
if (this->debug)
|
if (this->debug)
|
||||||
|
@@ -48,6 +48,7 @@ class PlateLines
|
|||||||
Config* config;
|
Config* config;
|
||||||
bool debug;
|
bool debug;
|
||||||
|
|
||||||
|
void cleanupColors(Mat inputImage, Mat outputImage);
|
||||||
Mat customGrayscaleConversion(Mat src);
|
Mat customGrayscaleConversion(Mat src);
|
||||||
void findLines(Mat inputImage);
|
void findLines(Mat inputImage);
|
||||||
vector<LineSegment> getLines(Mat edges, float sensitivityMultiplier, bool vertical);
|
vector<LineSegment> getLines(Mat edges, float sensitivityMultiplier, bool vertical);
|
||||||
|
Reference in New Issue
Block a user