diff --git a/src/openalpr/licenseplatecandidate.cpp b/src/openalpr/licenseplatecandidate.cpp index c4bf089..6fa2b31 100644 --- a/src/openalpr/licenseplatecandidate.cpp +++ b/src/openalpr/licenseplatecandidate.cpp @@ -47,9 +47,6 @@ void LicensePlateCandidate::recognize() Mat plate_bgr = Mat(frame, expandedRegion); 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); if (charRegion.confidence > 10) @@ -58,7 +55,7 @@ void LicensePlateCandidate::recognize() //Mat boogedy = charRegion.getPlateMask(); 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); vector smallPlateCorners = cornerFinder.findPlateCorners(); @@ -139,40 +136,3 @@ Mat LicensePlateCandidate::deSkewPlate(Mat inputImage, vector corners) 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 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); - } -} diff --git a/src/openalpr/licenseplatecandidate.h b/src/openalpr/licenseplatecandidate.h index 5d5c15f..b1bab3a 100644 --- a/src/openalpr/licenseplatecandidate.h +++ b/src/openalpr/licenseplatecandidate.h @@ -64,7 +64,6 @@ class LicensePlateCandidate Mat frame; Rect plateRegion; - void cleanupColors(Mat inputImage, Mat outputImage); Mat filterByCharacterHue(vector > charRegionContours); vector findPlateCorners(Mat inputImage, PlateLines plateLines, CharacterRegion charRegion); // top-left, top-right, bottom-right, bottom-left diff --git a/src/openalpr/platelines.cpp b/src/openalpr/platelines.cpp index e7f31e3..20e5efc 100644 --- a/src/openalpr/platelines.cpp +++ b/src/openalpr/platelines.cpp @@ -40,9 +40,20 @@ void PlateLines::processImage(Mat inputImage, CharacterRegion* charRegion, float timespec 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_size = 2; Mat element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) ); @@ -225,6 +236,44 @@ vector 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 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 PlateLines::getLines(Mat edges, float sensitivityMultiplier, bool vertical) { if (this->debug) diff --git a/src/openalpr/platelines.h b/src/openalpr/platelines.h index f95e65d..7d0839a 100644 --- a/src/openalpr/platelines.h +++ b/src/openalpr/platelines.h @@ -48,6 +48,7 @@ class PlateLines Config* config; bool debug; + void cleanupColors(Mat inputImage, Mat outputImage); Mat customGrayscaleConversion(Mat src); void findLines(Mat inputImage); vector getLines(Mat edges, float sensitivityMultiplier, bool vertical);