diff --git a/src/openalpr/licenseplatecandidate.cpp b/src/openalpr/licenseplatecandidate.cpp index 6666d93..6335516 100644 --- a/src/openalpr/licenseplatecandidate.cpp +++ b/src/openalpr/licenseplatecandidate.cpp @@ -57,8 +57,8 @@ void LicensePlateCandidate::recognize() PlateLines plateLines(config); //Mat boogedy = charRegion.getPlateMask(); - plateLines.processImage(charRegion.getPlateMask(), 1.15); - plateLines.processImage(plate_bgr_cleaned, 0.9); + plateLines.processImage(charRegion.getPlateMask(), &charRegion, 1.10); + plateLines.processImage(plate_bgr_cleaned, &charRegion, 0.9); PlateCorners cornerFinder(plate_bgr, &plateLines, &charRegion, config); vector smallPlateCorners = cornerFinder.findPlateCorners(); diff --git a/src/openalpr/platelines.cpp b/src/openalpr/platelines.cpp index b264481..e7f31e3 100644 --- a/src/openalpr/platelines.cpp +++ b/src/openalpr/platelines.cpp @@ -32,7 +32,7 @@ PlateLines::~PlateLines() { } -void PlateLines::processImage(Mat inputImage, float sensitivity) +void PlateLines::processImage(Mat inputImage, CharacterRegion* charRegion, float sensitivity) { if (this->debug) cout << "PlateLines findLines" << endl; @@ -40,6 +40,7 @@ void PlateLines::processImage(Mat inputImage, float sensitivity) timespec startTime; getTime(&startTime); + Mat smoothed(inputImage.size(), inputImage.type()); inputImage.copyTo(smoothed); int morph_elem = 2; @@ -48,11 +49,6 @@ void PlateLines::processImage(Mat inputImage, float sensitivity) morphologyEx( smoothed, smoothed, MORPH_CLOSE, element ); - morph_size = 1; - element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) ); - - //morphologyEx( thresholded, thresholded, MORPH_GRADIENT, element ); - morph_size = 1; element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) ); morphologyEx( smoothed, smoothed, MORPH_OPEN, element ); @@ -60,6 +56,15 @@ void PlateLines::processImage(Mat inputImage, float sensitivity) Mat edges(inputImage.size(), inputImage.type()); Canny(smoothed, edges, 66, 133); + // Create a mask that is dilated based on the detected characters + Mat mask = charRegion->charAnalysis->getCharacterMask(); + dilate(mask, mask, element); + bitwise_not(mask, mask); + + // AND canny edges with the character mask + bitwise_and(edges, mask, edges); + + vector hlines = this->getLines(edges, sensitivity, false); vector vlines = this->getLines(edges, sensitivity, true); for (int i = 0; i < hlines.size(); i++) diff --git a/src/openalpr/platelines.h b/src/openalpr/platelines.h index 49594a0..f95e65d 100644 --- a/src/openalpr/platelines.h +++ b/src/openalpr/platelines.h @@ -25,6 +25,7 @@ #include "utility.h" #include "binarize_wolf.h" #include "config.h" +#include "characterregion.h" using namespace cv; using namespace std; @@ -36,7 +37,7 @@ class PlateLines PlateLines(Config* config); virtual ~PlateLines(); - void processImage(Mat img, float sensitivity=1.0); + void processImage(Mat img, CharacterRegion* charRegion, float sensitivity=1.0); vector horizontalLines; vector verticalLines;