mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 05:00:54 +08:00
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:
@@ -57,8 +57,8 @@ void LicensePlateCandidate::recognize()
|
|||||||
PlateLines plateLines(config);
|
PlateLines plateLines(config);
|
||||||
//Mat boogedy = charRegion.getPlateMask();
|
//Mat boogedy = charRegion.getPlateMask();
|
||||||
|
|
||||||
plateLines.processImage(charRegion.getPlateMask(), 1.15);
|
plateLines.processImage(charRegion.getPlateMask(), &charRegion, 1.10);
|
||||||
plateLines.processImage(plate_bgr_cleaned, 0.9);
|
plateLines.processImage(plate_bgr_cleaned, &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();
|
||||||
|
@@ -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)
|
if (this->debug)
|
||||||
cout << "PlateLines findLines" << endl;
|
cout << "PlateLines findLines" << endl;
|
||||||
@@ -40,6 +40,7 @@ void PlateLines::processImage(Mat inputImage, float sensitivity)
|
|||||||
timespec startTime;
|
timespec startTime;
|
||||||
getTime(&startTime);
|
getTime(&startTime);
|
||||||
|
|
||||||
|
|
||||||
Mat smoothed(inputImage.size(), inputImage.type());
|
Mat smoothed(inputImage.size(), inputImage.type());
|
||||||
inputImage.copyTo(smoothed);
|
inputImage.copyTo(smoothed);
|
||||||
int morph_elem = 2;
|
int morph_elem = 2;
|
||||||
@@ -48,11 +49,6 @@ void PlateLines::processImage(Mat inputImage, float sensitivity)
|
|||||||
|
|
||||||
morphologyEx( smoothed, smoothed, MORPH_CLOSE, element );
|
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;
|
morph_size = 1;
|
||||||
element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );
|
element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );
|
||||||
morphologyEx( smoothed, smoothed, MORPH_OPEN, element );
|
morphologyEx( smoothed, smoothed, MORPH_OPEN, element );
|
||||||
@@ -60,6 +56,15 @@ void PlateLines::processImage(Mat inputImage, float sensitivity)
|
|||||||
Mat edges(inputImage.size(), inputImage.type());
|
Mat edges(inputImage.size(), inputImage.type());
|
||||||
Canny(smoothed, edges, 66, 133);
|
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> hlines = this->getLines(edges, sensitivity, false);
|
||||||
vector<LineSegment> vlines = this->getLines(edges, sensitivity, true);
|
vector<LineSegment> vlines = this->getLines(edges, sensitivity, true);
|
||||||
for (int i = 0; i < hlines.size(); i++)
|
for (int i = 0; i < hlines.size(); i++)
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
#include "binarize_wolf.h"
|
#include "binarize_wolf.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "characterregion.h"
|
||||||
|
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -36,7 +37,7 @@ class PlateLines
|
|||||||
PlateLines(Config* config);
|
PlateLines(Config* config);
|
||||||
virtual ~PlateLines();
|
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> horizontalLines;
|
||||||
vector<LineSegment> verticalLines;
|
vector<LineSegment> verticalLines;
|
||||||
|
Reference in New Issue
Block a user