Masking characters from canny filter before doing the hough transform to detect plate edges.

This should reduce the noise a bit and get rid of spurious edges detected in the middle of the plate
This commit is contained in:
Matt Hill
2014-03-25 21:48:17 -05:00
parent 1a0b51d72f
commit 0a41923da7
3 changed files with 15 additions and 9 deletions

View File

@@ -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<Point> smallPlateCorners = cornerFinder.findPlateCorners();

View File

@@ -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<LineSegment> hlines = this->getLines(edges, sensitivity, false);
vector<LineSegment> vlines = this->getLines(edges, sensitivity, true);
for (int i = 0; i < hlines.size(); i++)

View File

@@ -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<LineSegment> horizontalLines;
vector<LineSegment> verticalLines;