Inserted pipeline_data into additional places

This commit is contained in:
Matt Hill
2014-07-01 17:44:39 -04:00
parent 552caf5a05
commit b9422dc063
7 changed files with 38 additions and 46 deletions

View File

@@ -211,16 +211,19 @@ int main( int argc, const char** argv )
for (int z = 0; z < regions.size(); z++) for (int z = 0; z < regions.size(); z++)
{ {
PipelineData pipeline_data(frame, regions[z].rect, &config);
getTime(&startTime); getTime(&startTime);
char temp[5];
stateIdentifier.recognize(frame, regions[z].rect, temp); stateIdentifier.recognize(&pipeline_data);
getTime(&endTime); getTime(&endTime);
double stateidTime = diffclock(startTime, endTime); double stateidTime = diffclock(startTime, endTime);
cout << "\tRegion " << z << ": State ID time: " << stateidTime << "ms." << endl; cout << "\tRegion " << z << ": State ID time: " << stateidTime << "ms." << endl;
stateIdTimes.push_back(stateidTime); stateIdTimes.push_back(stateidTime);
getTime(&startTime); getTime(&startTime);
LicensePlateCandidate lp(frame, regions[z].rect, &config); LicensePlateCandidate lp(&pipeline_data);
lp.recognize(); lp.recognize();
getTime(&endTime); getTime(&endTime);
double analysisTime = diffclock(startTime, endTime); double analysisTime = diffclock(startTime, endTime);

View File

@@ -79,31 +79,26 @@ int main( int argc, const char** argv )
cout << fullpath << endl; cout << fullpath << endl;
frame = imread( fullpath.c_str() ); frame = imread( fullpath.c_str() );
char code[4]; PipelineData pipeline_data(frame, Rect(0, 0, frame.cols, frame.rows), &config);
int confidence = identifier.recognize(frame, code); identifier.recognize(&pipeline_data);
if (confidence <= 20) if (pipeline_data.region_confidence <= 20)
{ {
code[0] = 'z'; pipeline_data.region_code = 'zz';
code[1] = 'z'; pipeline_data.region_confidence = 100;
confidence = 100;
} }
else
//imshow("Plate", frame);
if (confidence > 20)
{ {
cout << confidence << " : " << code; cout << pipeline_data.region_confidence << " : " << pipeline_data.region_code;
ostringstream convert; // stream used for the conversion ostringstream convert; // stream used for the conversion
convert << i; // insert the textual representation of 'Number' in the characters in the stream 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() ); system( copyCommand.c_str() );
waitKey(50); waitKey(50);
//while ((char) waitKey(50) != 'c') { } //while ((char) waitKey(50) != 'c') { }
} }
else
waitKey(50);
} }
} }
} }

View File

@@ -186,12 +186,12 @@ void plateAnalysisThread(void* arg)
if (dispatcher->config->debugGeneral) if (dispatcher->config->debugGeneral)
cout << "Thread: " << tthread::this_thread::get_id() << " loop " << ++loop_count << endl; 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; timespec platestarttime;
getTime(&platestarttime); getTime(&platestarttime);
LicensePlateCandidate lp(img, plateRegion.rect, dispatcher->config); LicensePlateCandidate lp(&pipeline_data);
lp.recognize(); lp.recognize();
@@ -220,7 +220,7 @@ void plateAnalysisThread(void* arg)
if (dispatcher->detectRegion) if (dispatcher->detectRegion)
{ {
char statecode[4]; char statecode[4];
plateResult.regionConfidence = dispatcher->stateIdentifier->recognize(img, plateRegion.rect, statecode); plateResult.regionConfidence = dispatcher->stateIdentifier->recognize(&pipeline_data);
if (plateResult.regionConfidence > 0) if (plateResult.regionConfidence > 0)
{ {
plateResult.region = statecode; plateResult.region = statecode;

View File

@@ -37,6 +37,8 @@
#include "cjson.h" #include "cjson.h"
#include "pipeline_data.h"
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>

View File

@@ -22,7 +22,7 @@
using namespace cv; using namespace cv;
using namespace std; using namespace std;
CharacterSegmenter::CharacterSegmenter(Mat img, bool invertedColors, Config* config) CharacterSegmenter::CharacterSegmenter(Mat img_gray, bool invertedColors, Config* config)
{ {
this->config = config; this->config = config;
@@ -36,8 +36,6 @@ CharacterSegmenter::CharacterSegmenter(Mat img, bool invertedColors, Config* con
timespec startTime; timespec startTime;
getTime(&startTime); getTime(&startTime);
Mat img_gray(img.size(), CV_8U);
cvtColor( img, img_gray, CV_BGR2GRAY );
medianBlur(img_gray, img_gray, 3); medianBlur(img_gray, img_gray, 3);

View File

@@ -22,12 +22,11 @@
using namespace std; using namespace std;
using namespace cv; 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() LicensePlateCandidate::~LicensePlateCandidate()
@@ -42,19 +41,16 @@ void LicensePlateCandidate::recognize()
this->confidence = 0; this->confidence = 0;
int expandX = round(this->plateRegion.width * 0.20); int expandX = round(this->pipeline_data->regionOfInterest.width * 0.20);
int expandY = round(this->plateRegion.height * 0.15); int expandY = round(this->pipeline_data->regionOfInterest.height * 0.15);
// expand box by 15% in all directions // 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); pipeline_data->crop_gray = Mat(this->pipeline_data->grayImg, expandedRegion);
resize(plate_bgr, plate_bgr, Size(config->templateWidthPx, config->templateHeightPx)); resize(pipeline_data->crop_gray, pipeline_data->crop_gray, Size(config->templateWidthPx, config->templateHeightPx));
Mat plate_gray;
cvtColor(plate_bgr, plate_gray, CV_BGR2GRAY);
CharacterRegion charRegion(plate_bgr, config); CharacterRegion charRegion(pipeline_data->crop_gray, config);
if (charRegion.confidence > 10) if (charRegion.confidence > 10)
{ {
@@ -62,16 +58,16 @@ void LicensePlateCandidate::recognize()
//Mat boogedy = charRegion.getPlateMask(); //Mat boogedy = charRegion.getPlateMask();
plateLines.processImage(charRegion.getPlateMask(), &charRegion, 1.10); 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<Point> smallPlateCorners = cornerFinder.findPlateCorners(); vector<Point> smallPlateCorners = cornerFinder.findPlateCorners();
if (cornerFinder.confidence > 0) 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); charSegmenter = new CharacterSegmenter(deskewed, charRegion.thresholdsInverted(), config);
@@ -122,7 +118,7 @@ Mat LicensePlateCandidate::deSkewPlate(Mat inputImage, vector<Point2f> corners)
width = round(((float) height) * aspect); 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 // Corners of the destination image
vector<Point2f> quad_pts; vector<Point2f> quad_pts;

View File

@@ -34,7 +34,7 @@
#include "charactersegmenter.h" #include "charactersegmenter.h"
#include "platecorners.h" #include "platecorners.h"
#include "config.h" #include "config.h"
#include "pipeline_data.h"
//vector<Rect> getCharacterRegions(Mat frame, vector<Rect> regionsOfInterest); //vector<Rect> getCharacterRegions(Mat frame, vector<Rect> regionsOfInterest);
//vector<RotatedRect> getCharSegmentsBetweenLines(Mat img, vector<vector<Point> > contours, LineSegment top, LineSegment bottom); //vector<RotatedRect> getCharSegmentsBetweenLines(Mat img, vector<vector<Point> > contours, LineSegment top, LineSegment bottom);
@@ -43,7 +43,7 @@ class LicensePlateCandidate
{ {
public: public:
LicensePlateCandidate(cv::Mat frame, cv::Rect regionOfInterest, Config* config); LicensePlateCandidate(PipelineData* pipeline_data);
virtual ~LicensePlateCandidate(); virtual ~LicensePlateCandidate();
float confidence; // 0-100 float confidence; // 0-100
@@ -56,11 +56,9 @@ class LicensePlateCandidate
CharacterSegmenter* charSegmenter; CharacterSegmenter* charSegmenter;
private: private:
PipelineData* pipeline_data;
Config* config; Config* config;
cv::Mat frame;
cv::Rect plateRegion;
cv::Mat filterByCharacterHue(std::vector<std::vector<cv::Point> > charRegionContours); cv::Mat filterByCharacterHue(std::vector<std::vector<cv::Point> > charRegionContours);
std::vector<cv::Point> findPlateCorners(cv::Mat inputImage, PlateLines plateLines, CharacterRegion charRegion); // top-left, top-right, bottom-right, bottom-left std::vector<cv::Point> findPlateCorners(cv::Mat inputImage, PlateLines plateLines, CharacterRegion charRegion); // top-left, top-right, bottom-right, bottom-left