From b9422dc0630937d7894ce490330a1e3a094523bd Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Tue, 1 Jul 2014 17:44:39 -0400 Subject: [PATCH] Inserted pipeline_data into additional places --- src/misc_utilities/benchmark/benchmark.cpp | 9 ++++-- src/misc_utilities/sortstate.cpp | 23 ++++++---------- src/openalpr/alpr_impl.cpp | 6 ++-- src/openalpr/alpr_impl.h | 2 ++ src/openalpr/charactersegmenter.cpp | 4 +-- src/openalpr/licenseplatecandidate.cpp | 32 ++++++++++------------ src/openalpr/licenseplatecandidate.h | 8 ++---- 7 files changed, 38 insertions(+), 46 deletions(-) diff --git a/src/misc_utilities/benchmark/benchmark.cpp b/src/misc_utilities/benchmark/benchmark.cpp index 7a4f23b..51ead18 100644 --- a/src/misc_utilities/benchmark/benchmark.cpp +++ b/src/misc_utilities/benchmark/benchmark.cpp @@ -211,16 +211,19 @@ int main( int argc, const char** argv ) for (int z = 0; z < regions.size(); z++) { + + PipelineData pipeline_data(frame, regions[z].rect, &config); + getTime(&startTime); - char temp[5]; - stateIdentifier.recognize(frame, regions[z].rect, temp); + + stateIdentifier.recognize(&pipeline_data); getTime(&endTime); double stateidTime = diffclock(startTime, endTime); cout << "\tRegion " << z << ": State ID time: " << stateidTime << "ms." << endl; stateIdTimes.push_back(stateidTime); getTime(&startTime); - LicensePlateCandidate lp(frame, regions[z].rect, &config); + LicensePlateCandidate lp(&pipeline_data); lp.recognize(); getTime(&endTime); double analysisTime = diffclock(startTime, endTime); diff --git a/src/misc_utilities/sortstate.cpp b/src/misc_utilities/sortstate.cpp index 68770ef..eff5229 100644 --- a/src/misc_utilities/sortstate.cpp +++ b/src/misc_utilities/sortstate.cpp @@ -79,31 +79,26 @@ int main( int argc, const char** argv ) cout << fullpath << endl; frame = imread( fullpath.c_str() ); - char code[4]; - int confidence = identifier.recognize(frame, code); + PipelineData pipeline_data(frame, Rect(0, 0, frame.cols, frame.rows), &config); + identifier.recognize(&pipeline_data); - if (confidence <= 20) + if (pipeline_data.region_confidence <= 20) { - code[0] = 'z'; - code[1] = 'z'; - confidence = 100; + pipeline_data.region_code = 'zz'; + pipeline_data.region_confidence = 100; } - - //imshow("Plate", frame); - if (confidence > 20) - { - cout << confidence << " : " << code; + else + { + cout << pipeline_data.region_confidence << " : " << pipeline_data.region_code; ostringstream convert; // stream used for the conversion convert << i; // insert the textual representation of 'Number' in the characters in the stream - string copyCommand = "cp \"" + fullpath + "\" " + outDir + code + convert.str() + ".png"; + string copyCommand = "cp \"" + fullpath + "\" " + outDir + pipeline_data.region_code + convert.str() + ".png"; system( copyCommand.c_str() ); waitKey(50); //while ((char) waitKey(50) != 'c') { } } - else - waitKey(50); } } } diff --git a/src/openalpr/alpr_impl.cpp b/src/openalpr/alpr_impl.cpp index 2aa42e6..42d297b 100644 --- a/src/openalpr/alpr_impl.cpp +++ b/src/openalpr/alpr_impl.cpp @@ -186,12 +186,12 @@ void plateAnalysisThread(void* arg) if (dispatcher->config->debugGeneral) cout << "Thread: " << tthread::this_thread::get_id() << " loop " << ++loop_count << endl; - Mat img = dispatcher->getImageCopy(); + PipelineData pipeline_data(dispatcher->getImageCopy(), plateRegion.rect, dispatcher->config); timespec platestarttime; getTime(&platestarttime); - LicensePlateCandidate lp(img, plateRegion.rect, dispatcher->config); + LicensePlateCandidate lp(&pipeline_data); lp.recognize(); @@ -220,7 +220,7 @@ void plateAnalysisThread(void* arg) if (dispatcher->detectRegion) { char statecode[4]; - plateResult.regionConfidence = dispatcher->stateIdentifier->recognize(img, plateRegion.rect, statecode); + plateResult.regionConfidence = dispatcher->stateIdentifier->recognize(&pipeline_data); if (plateResult.regionConfidence > 0) { plateResult.region = statecode; diff --git a/src/openalpr/alpr_impl.h b/src/openalpr/alpr_impl.h index 64f8a7b..77db817 100644 --- a/src/openalpr/alpr_impl.h +++ b/src/openalpr/alpr_impl.h @@ -37,6 +37,8 @@ #include "cjson.h" +#include "pipeline_data.h" + #include diff --git a/src/openalpr/charactersegmenter.cpp b/src/openalpr/charactersegmenter.cpp index 9a07c95..87007a1 100644 --- a/src/openalpr/charactersegmenter.cpp +++ b/src/openalpr/charactersegmenter.cpp @@ -22,7 +22,7 @@ using namespace cv; using namespace std; -CharacterSegmenter::CharacterSegmenter(Mat img, bool invertedColors, Config* config) +CharacterSegmenter::CharacterSegmenter(Mat img_gray, bool invertedColors, Config* config) { this->config = config; @@ -36,8 +36,6 @@ CharacterSegmenter::CharacterSegmenter(Mat img, bool invertedColors, Config* con timespec startTime; getTime(&startTime); - Mat img_gray(img.size(), CV_8U); - cvtColor( img, img_gray, CV_BGR2GRAY ); medianBlur(img_gray, img_gray, 3); diff --git a/src/openalpr/licenseplatecandidate.cpp b/src/openalpr/licenseplatecandidate.cpp index b15fad0..15a40c6 100644 --- a/src/openalpr/licenseplatecandidate.cpp +++ b/src/openalpr/licenseplatecandidate.cpp @@ -22,12 +22,11 @@ using namespace std; using namespace cv; -LicensePlateCandidate::LicensePlateCandidate(Mat frame, Rect regionOfInterest, Config* config) +LicensePlateCandidate::LicensePlateCandidate(PipelineData* pipeline_data) { - this->config = config; + this->pipeline_data = pipeline_data; + this->config = pipeline_data->config; - this->frame = frame; - this->plateRegion = regionOfInterest; } LicensePlateCandidate::~LicensePlateCandidate() @@ -42,19 +41,16 @@ void LicensePlateCandidate::recognize() this->confidence = 0; - int expandX = round(this->plateRegion.width * 0.20); - int expandY = round(this->plateRegion.height * 0.15); + int expandX = round(this->pipeline_data->regionOfInterest.width * 0.20); + int expandY = round(this->pipeline_data->regionOfInterest.height * 0.15); // expand box by 15% in all directions - Rect expandedRegion = expandRect( this->plateRegion, expandX, expandY, frame.cols, frame.rows) ; + Rect expandedRegion = expandRect( this->pipeline_data->regionOfInterest, expandX, expandY, this->pipeline_data->grayImg.cols, this->pipeline_data->grayImg.rows) ; - Mat plate_bgr = Mat(frame, expandedRegion); - resize(plate_bgr, plate_bgr, Size(config->templateWidthPx, config->templateHeightPx)); - - Mat plate_gray; - cvtColor(plate_bgr, plate_gray, CV_BGR2GRAY); + pipeline_data->crop_gray = Mat(this->pipeline_data->grayImg, expandedRegion); + resize(pipeline_data->crop_gray, pipeline_data->crop_gray, Size(config->templateWidthPx, config->templateHeightPx)); - CharacterRegion charRegion(plate_bgr, config); + CharacterRegion charRegion(pipeline_data->crop_gray, config); if (charRegion.confidence > 10) { @@ -62,16 +58,16 @@ void LicensePlateCandidate::recognize() //Mat boogedy = charRegion.getPlateMask(); plateLines.processImage(charRegion.getPlateMask(), &charRegion, 1.10); - plateLines.processImage(plate_gray, &charRegion, 0.9); + plateLines.processImage(pipeline_data->crop_gray, &charRegion, 0.9); - PlateCorners cornerFinder(plate_bgr, &plateLines, &charRegion, config); + PlateCorners cornerFinder(pipeline_data->crop_gray, &plateLines, &charRegion, config); vector smallPlateCorners = cornerFinder.findPlateCorners(); if (cornerFinder.confidence > 0) { - this->plateCorners = transformPointsToOriginalImage(frame, plate_bgr, expandedRegion, smallPlateCorners); + this->plateCorners = transformPointsToOriginalImage(this->pipeline_data->grayImg, pipeline_data->crop_gray, expandedRegion, smallPlateCorners); - this->deskewed = deSkewPlate(frame, this->plateCorners); + this->deskewed = deSkewPlate(this->pipeline_data->grayImg, this->plateCorners); charSegmenter = new CharacterSegmenter(deskewed, charRegion.thresholdsInverted(), config); @@ -122,7 +118,7 @@ Mat LicensePlateCandidate::deSkewPlate(Mat inputImage, vector corners) width = round(((float) height) * aspect); } - Mat deskewed(height, width, frame.type()); + Mat deskewed(height, width, this->pipeline_data->grayImg.type()); // Corners of the destination image vector quad_pts; diff --git a/src/openalpr/licenseplatecandidate.h b/src/openalpr/licenseplatecandidate.h index e12be32..1e71b62 100644 --- a/src/openalpr/licenseplatecandidate.h +++ b/src/openalpr/licenseplatecandidate.h @@ -34,7 +34,7 @@ #include "charactersegmenter.h" #include "platecorners.h" #include "config.h" - +#include "pipeline_data.h" //vector getCharacterRegions(Mat frame, vector regionsOfInterest); //vector getCharSegmentsBetweenLines(Mat img, vector > contours, LineSegment top, LineSegment bottom); @@ -43,7 +43,7 @@ class LicensePlateCandidate { public: - LicensePlateCandidate(cv::Mat frame, cv::Rect regionOfInterest, Config* config); + LicensePlateCandidate(PipelineData* pipeline_data); virtual ~LicensePlateCandidate(); float confidence; // 0-100 @@ -56,11 +56,9 @@ class LicensePlateCandidate CharacterSegmenter* charSegmenter; private: - + PipelineData* pipeline_data; Config* config; - cv::Mat frame; - cv::Rect plateRegion; cv::Mat filterByCharacterHue(std::vector > charRegionContours); std::vector findPlateCorners(cv::Mat inputImage, PlateLines plateLines, CharacterRegion charRegion); // top-left, top-right, bottom-right, bottom-left