From 1801733061950d8818a1f0b0faf658548ac41ded Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Thu, 28 Aug 2014 21:57:10 -0400 Subject: [PATCH] Fixed compiler warnings (signed/unsigned comparisons, unused variables) --- src/openalpr/alpr_impl.cpp | 18 ++--- src/openalpr/alpr_impl.h | 2 +- src/openalpr/binarize_wolf.cpp | 1 - src/openalpr/characteranalysis.cpp | 70 ++++++++--------- src/openalpr/characterregion.cpp | 4 +- src/openalpr/colorfilter.cpp | 6 +- src/openalpr/config.h | 6 +- src/openalpr/detection/detector.cpp | 6 +- src/openalpr/detection/detectorcpu.cpp | 2 +- src/openalpr/featurematcher.cpp | 32 ++++---- src/openalpr/licenseplatecandidate.cpp | 2 +- src/openalpr/ocr.cpp | 4 +- src/openalpr/pipeline_data.cpp | 2 +- src/openalpr/platelines.cpp | 6 +- .../segmentation/charactersegmenter.cpp | 78 +++++++++---------- .../segmentation/verticalhistogram.cpp | 10 +-- src/openalpr/segmentation/verticalhistogram.h | 2 +- src/openalpr/utility.cpp | 10 ++- src/openalpr/utility.h | 3 +- 19 files changed, 133 insertions(+), 131 deletions(-) diff --git a/src/openalpr/alpr_impl.cpp b/src/openalpr/alpr_impl.cpp index 28eaad6..a95d7e7 100644 --- a/src/openalpr/alpr_impl.cpp +++ b/src/openalpr/alpr_impl.cpp @@ -103,7 +103,7 @@ AlprFullDetails AlprImpl::recognizeFullDetails(cv::Mat img, std::vectordetect(img, regionsOfInterest); // Get the number of threads specified and make sure the value is sane (cannot be greater than CPU cores or less than 1) - int numThreads = config->multithreading_cores; + uint numThreads = config->multithreading_cores; if (numThreads > tthread::thread::hardware_concurrency()) numThreads = tthread::thread::hardware_concurrency(); if (numThreads <= 0) @@ -116,7 +116,7 @@ AlprFullDetails AlprImpl::recognizeFullDetails(cv::Mat img, std::vector threads; - for (int i = 0; i < numThreads; i++) + for (uint i = 0; i < numThreads; i++) { tthread::thread * t = new tthread::thread(plateAnalysisThread, (void *) &dispatcher); threads.push_back(t); @@ -139,12 +139,12 @@ AlprFullDetails AlprImpl::recognizeFullDetails(cv::Mat img, std::vectordebugGeneral && config->debugShowImages) { - for (int i = 0; i < response.plateRegions.size(); i++) + for (uint i = 0; i < response.plateRegions.size(); i++) { rectangle(img, response.plateRegions[i].rect, Scalar(0, 0, 255), 2); } - for (int i = 0; i < dispatcher.getRecognitionResults().size(); i++) + for (uint i = 0; i < dispatcher.getRecognitionResults().size(); i++) { for (int z = 0; z < 4; z++) { @@ -228,7 +228,7 @@ void plateAnalysisThread(void* arg) { // Not a valid plate // Check if this plate has any children, if so, send them back up to the dispatcher for processing - for (int childidx = 0; childidx < plateRegion.children.size(); childidx++) + for (uint childidx = 0; childidx < plateRegion.children.size(); childidx++) { dispatcher->appendPlate(plateRegion.children[childidx]); } @@ -265,7 +265,7 @@ void plateAnalysisThread(void* arg) int bestPlateIndex = 0; - for (int pp = 0; pp < ppResults.size(); pp++) + for (uint pp = 0; pp < ppResults.size(); pp++) { if (pp >= dispatcher->topN) break; @@ -321,7 +321,7 @@ void plateAnalysisThread(void* arg) std::vector AlprImpl::convertRects(std::vector regionsOfInterest) { std::vector rectRegions; - for (int i = 0; i < regionsOfInterest.size(); i++) + for (uint i = 0; i < regionsOfInterest.size(); i++) { rectRegions.push_back(cv::Rect(regionsOfInterest[i].x, regionsOfInterest[i].y, regionsOfInterest[i].width, regionsOfInterest[i].height)); } @@ -341,7 +341,7 @@ string AlprImpl::toJson(const vector< AlprResult > results, double processing_ti } cJSON_AddItemToObject(root, "results", jsonResults=cJSON_CreateArray()); - for (int i = 0; i < results.size(); i++) + for (uint i = 0; i < results.size(); i++) { cJSON *resultObj = createJsonObj( &results[i] ); cJSON_AddItemToArray(jsonResults, resultObj); @@ -389,7 +389,7 @@ cJSON* AlprImpl::createJsonObj(const AlprResult* result) cJSON_AddItemToObject(root, "candidates", candidates=cJSON_CreateArray()); - for (int i = 0; i < result->topNPlates.size(); i++) + for (uint i = 0; i < result->topNPlates.size(); i++) { cJSON *candidate_object; candidate_object = cJSON_CreateObject(); diff --git a/src/openalpr/alpr_impl.h b/src/openalpr/alpr_impl.h index 91f8a6d..4c72162 100644 --- a/src/openalpr/alpr_impl.h +++ b/src/openalpr/alpr_impl.h @@ -167,7 +167,7 @@ class PlateDispatcher OCR* ocr; Config* config; - int topN; + uint topN; bool detectRegion; std::string defaultRegion; diff --git a/src/openalpr/binarize_wolf.cpp b/src/openalpr/binarize_wolf.cpp index 38b6d85..37931b1 100644 --- a/src/openalpr/binarize_wolf.cpp +++ b/src/openalpr/binarize_wolf.cpp @@ -122,7 +122,6 @@ void NiblackSauvolaWolfJolion (Mat im, Mat output, NiblackVersion version, int x_lastth = im.cols-wxh-1; int y_lastth = im.rows-wyh-1; int y_firstth= wyh; - int mx, my; // Create local statistics and store them in a float matrices Mat map_m = Mat::zeros (im.rows, im.cols, CV_32F); diff --git a/src/openalpr/characteranalysis.cpp b/src/openalpr/characteranalysis.cpp index c70691f..3755859 100644 --- a/src/openalpr/characteranalysis.cpp +++ b/src/openalpr/characteranalysis.cpp @@ -49,7 +49,7 @@ void CharacterAnalysis::analyze() timespec startTime; getTime(&startTime); - for (int i = 0; i < pipeline_data->thresholds.size(); i++) + for (uint i = 0; i < pipeline_data->thresholds.size(); i++) { vector > contours; vector hierarchy; @@ -76,7 +76,7 @@ void CharacterAnalysis::analyze() getTime(&startTime); - for (int i = 0; i < pipeline_data->thresholds.size(); i++) + for (uint i = 0; i < pipeline_data->thresholds.size(); i++) { vector goodIndices = this->filter(pipeline_data->thresholds[i], allContours[i], allHierarchy[i]); charSegments.push_back(goodIndices); @@ -97,7 +97,7 @@ void CharacterAnalysis::analyze() if (hasPlateMask) { // Filter out bad contours now that we have an outer box mask... - for (int i = 0; i < pipeline_data->thresholds.size(); i++) + for (uint i = 0; i < pipeline_data->thresholds.size(); i++) { charSegments[i] = filterByOuterMask(allContours[i], allHierarchy[i], charSegments[i]); } @@ -105,7 +105,7 @@ void CharacterAnalysis::analyze() int bestFitScore = -1; int bestFitIndex = -1; - for (int i = 0; i < pipeline_data->thresholds.size(); i++) + for (uint i = 0; i < pipeline_data->thresholds.size(); i++) { //vector goodIndices = this->filter(thresholds[i], allContours[i], allHierarchy[i]); //charSegments.push_back(goodIndices); @@ -139,7 +139,7 @@ void CharacterAnalysis::analyze() cvtColor(img_contours, img_contours, CV_GRAY2RGB); vector > allowedContours; - for (int i = 0; i < bestContours.size(); i++) + for (uint i = 0; i < bestContours.size(); i++) { if (bestCharSegments[i]) allowedContours.push_back(bestContours[i]); @@ -186,7 +186,7 @@ void CharacterAnalysis::analyze() int CharacterAnalysis::getGoodIndicesCount(vector goodIndices) { int count = 0; - for (int i = 0; i < goodIndices.size(); i++) + for (uint i = 0; i < goodIndices.size(); i++) { if (goodIndices[i]) count++; @@ -207,14 +207,14 @@ Mat CharacterAnalysis::findOuterBoxMask() if (this->config->debugCharAnalysis) cout << "CharacterAnalysis::findOuterBoxMask" << endl; - for (int imgIndex = 0; imgIndex < allContours.size(); imgIndex++) + for (uint imgIndex = 0; imgIndex < allContours.size(); imgIndex++) { //vector charContours = filter(thresholds[imgIndex], allContours[imgIndex], allHierarchy[imgIndex]); int charsRecognized = 0; int parentId = -1; bool hasParent = false; - for (int i = 0; i < charSegments[imgIndex].size(); i++) + for (uint i = 0; i < charSegments[imgIndex].size(); i++) { if (charSegments[imgIndex][i]) charsRecognized++; if (charSegments[imgIndex][i] && allHierarchy[imgIndex][i][3] != -1) @@ -253,9 +253,9 @@ Mat CharacterAnalysis::findOuterBoxMask() int longestChildIndex = -1; double longestChildLength = 0; // Find the child with the longest permiter/arc length ( just for kicks) - for (int i = 0; i < allContours[winningIndex].size(); i++) + for (uint i = 0; i < allContours[winningIndex].size(); i++) { - for (int j = 0; j < allContours[winningIndex].size(); j++) + for (uint j = 0; j < allContours[winningIndex].size(); j++) { if (allHierarchy[winningIndex][j][3] == winningParentId) { @@ -301,7 +301,7 @@ Mat CharacterAnalysis::findOuterBoxMask() findContours(mask, contoursSecondRound, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); int biggestContourIndex = -1; double largestArea = 0; - for (int c = 0; c < contoursSecondRound.size(); c++) + for (uint c = 0; c < contoursSecondRound.size(); c++) { double area = contourArea(contoursSecondRound[c]); if (area > largestArea) @@ -360,7 +360,7 @@ Mat CharacterAnalysis::getCharacterMask() { Mat charMask = Mat::zeros(bestThreshold.size(), CV_8U); - for (int i = 0; i < bestContours.size(); i++) + for (uint i = 0; i < bestContours.size(); i++) { if (bestCharSegments[i] == false) continue; @@ -389,7 +389,7 @@ vector CharacterAnalysis::getBestVotedLines(Mat img, vector vector charRegions; - for (int i = 0; i < contours.size(); i++) + for (uint i = 0; i < contours.size(); i++) { if (goodIndices[i]) charRegions.push_back(boundingRect(contours[i])); @@ -405,9 +405,9 @@ vector CharacterAnalysis::getBestVotedLines(Mat img, vector vector topLines; vector bottomLines; // Iterate through each possible char and find all possible lines for the top and bottom of each char segment - for (int i = 0; i < charRegions.size() - 1; i++) + for (uint i = 0; i < charRegions.size() - 1; i++) { - for (int k = i+1; k < charRegions.size(); k++) + for (uint k = i+1; k < charRegions.size(); k++) { //Mat tempImg; //result.copyTo(tempImg); @@ -471,13 +471,13 @@ vector CharacterAnalysis::getBestVotedLines(Mat img, vector int bestScoreDistance = -1; // Line segment distance is used as a tie breaker // Now, among all possible lines, find the one that is the best fit - for (int i = 0; i < topLines.size(); i++) + for (uint i = 0; i < topLines.size(); i++) { float SCORING_MIN_THRESHOLD = 0.97; float SCORING_MAX_THRESHOLD = 1.03; int curScore = 0; - for (int charidx = 0; charidx < charRegions.size(); charidx++) + for (uint charidx = 0; charidx < charRegions.size(); charidx++) { float topYPos = topLines[i].getPointAt(charRegions[charidx].x); float botYPos = bottomLines[i].getPointAt(charRegions[charidx].x); @@ -550,7 +550,7 @@ vector CharacterAnalysis::filter(Mat img, vector > contours, int goodIndicesCount; vector goodIndices(contours.size()); - for (int z = 0; z < goodIndices.size(); z++) goodIndices[z] = true; + for (uint z = 0; z < goodIndices.size(); z++) goodIndices[z] = true; goodIndices = this->filterByBoxSize(contours, goodIndices, STARTING_MIN_HEIGHT + (i * HEIGHT_STEP), STARTING_MAX_HEIGHT + (i * HEIGHT_STEP)); @@ -585,10 +585,10 @@ vector CharacterAnalysis::filterByBoxSize(vector< vector< Point> > contour float aspecttolerance=0.25; vector includedIndices(contours.size()); - for (int j = 0; j < contours.size(); j++) + for (uint j = 0; j < contours.size(); j++) includedIndices.push_back(false); - for (int i = 0; i < contours.size(); i++) + for (uint i = 0; i < contours.size(); i++) { if (goodIndices[i] == false) continue; @@ -614,10 +614,10 @@ vector CharacterAnalysis::filterByBoxSize(vector< vector< Point> > contour vector< bool > CharacterAnalysis::filterContourHoles(vector< vector< Point > > contours, vector< Vec4i > hierarchy, vector< bool > goodIndices) { vector includedIndices(contours.size()); - for (int j = 0; j < contours.size(); j++) + for (uint j = 0; j < contours.size(); j++) includedIndices.push_back(false); - for (int i = 0; i < contours.size(); i++) + for (uint i = 0; i < contours.size(); i++) { if (goodIndices[i] == false) continue; @@ -646,13 +646,13 @@ vector< bool > CharacterAnalysis::filterContourHoles(vector< vector< Point > > c vector CharacterAnalysis::filterByParentContour( vector< vector< Point> > contours, vector hierarchy, vector goodIndices) { vector includedIndices(contours.size()); - for (int j = 0; j < contours.size(); j++) + for (uint j = 0; j < contours.size(); j++) includedIndices[j] = false; vector parentIDs; vector votes; - for (int i = 0; i < contours.size(); i++) + for (uint i = 0; i < contours.size(); i++) { if (goodIndices[i] == false) continue; @@ -660,7 +660,7 @@ vector CharacterAnalysis::filterByParentContour( vector< vector< Point> > int voteIndex = -1; int parentID = hierarchy[i][3]; // check if parentID is already in the lsit - for (int j = 0; j < parentIDs.size(); j++) + for (uint j = 0; j < parentIDs.size(); j++) { if (parentIDs[j] == parentID) { @@ -683,7 +683,7 @@ vector CharacterAnalysis::filterByParentContour( vector< vector< Point> > int totalVotes = 0; int winningParentId = 0; int highestVotes = 0; - for (int i = 0; i < parentIDs.size(); i++) + for (uint i = 0; i < parentIDs.size(); i++) { if (votes[i] > highestVotes) { @@ -694,7 +694,7 @@ vector CharacterAnalysis::filterByParentContour( vector< vector< Point> > } // Now filter out all the contours with a different parent ID (assuming the totalVotes > 2) - for (int i = 0; i < contours.size(); i++) + for (uint i = 0; i < contours.size(); i++) { if (goodIndices[i] == false) continue; @@ -718,7 +718,7 @@ vector CharacterAnalysis::filterBetweenLines(Mat img, vector static float MAX_DISTANCE_PERCENT_FROM_LINES = 0.15; vector includedIndices(contours.size()); - for (int j = 0; j < contours.size(); j++) + for (uint j = 0; j < contours.size(); j++) includedIndices[j] = false; if (outerPolygon.size() == 0) @@ -741,7 +741,7 @@ vector CharacterAnalysis::filterBetweenLines(Mat img, vector fillConvexPoly(outerMask, outerPolygon.data(), outerPolygon.size(), Scalar(255,255,255)); // For each contour, determine if enough of it is between the lines to qualify - for (int i = 0; i < contours.size(); i++) + for (uint i = 0; i < contours.size(); i++) { if (goodIndices[i] == false) continue; @@ -767,7 +767,7 @@ vector CharacterAnalysis::filterBetweenLines(Mat img, vector double totalArea = contourArea(contours[i]); double areaBetweenLines = 0; - for (int tempContourIdx = 0; tempContourIdx < tempContours.size(); tempContourIdx++) + for (uint tempContourIdx = 0; tempContourIdx < tempContours.size(); tempContourIdx++) { areaBetweenLines += contourArea(tempContours[tempContourIdx]); } @@ -789,7 +789,7 @@ vector CharacterAnalysis::filterBetweenLines(Mat img, vector int highPointValue = 999999999; int lowPointIndex = 0; int lowPointValue = 0; - for (int cidx = 0; cidx < contours[i].size(); cidx++) + for (uint cidx = 0; cidx < contours[i].size(); cidx++) { if (contours[i][cidx].y < highPointValue) { @@ -831,7 +831,7 @@ std::vector< bool > CharacterAnalysis::filterByOuterMask(vector< vector< Point > return goodIndices; vector passingIndices; - for (int i = 0; i < goodIndices.size(); i++) + for (uint i = 0; i < goodIndices.size(); i++) passingIndices.push_back(false); Mat tempMaskedContour = Mat::zeros(plateMask.size(), CV_8U); @@ -840,7 +840,7 @@ std::vector< bool > CharacterAnalysis::filterByOuterMask(vector< vector< Point > int charsInsideMask = 0; int totalChars = 0; - for (int i=0; i < goodIndices.size(); i++) + for (uint i=0; i < goodIndices.size(); i++) { if (goodIndices[i] == false) continue; @@ -921,12 +921,12 @@ vector CharacterAnalysis::getCharArea() int leftX = MAX; int rightX = MIN; - for (int i = 0; i < bestContours.size(); i++) + for (uint i = 0; i < bestContours.size(); i++) { if (bestCharSegments[i] == false) continue; - for (int z = 0; z < bestContours[i].size(); z++) + for (uint z = 0; z < bestContours[i].size(); z++) { if (bestContours[i][z].x < leftX) leftX = bestContours[i][z].x; diff --git a/src/openalpr/characterregion.cpp b/src/openalpr/characterregion.cpp index 15106f7..61ce02b 100644 --- a/src/openalpr/characterregion.cpp +++ b/src/openalpr/characterregion.cpp @@ -43,7 +43,7 @@ CharacterRegion::CharacterRegion(PipelineData* pipeline_data) if (this->debug && charAnalysis->linePolygon.size() > 0) { vector tempDash; - for (int z = 0; z < pipeline_data->thresholds.size(); z++) + for (uint z = 0; z < pipeline_data->thresholds.size(); z++) { Mat tmp(pipeline_data->thresholds[z].size(), pipeline_data->thresholds[z].type()); pipeline_data->thresholds[z].copyTo(tmp); @@ -56,7 +56,7 @@ CharacterRegion::CharacterRegion(PipelineData* pipeline_data) charAnalysis->bestThreshold.copyTo(bestVal); cvtColor(bestVal, bestVal, CV_GRAY2BGR); - for (int z = 0; z < charAnalysis->bestContours.size(); z++) + for (uint z = 0; z < charAnalysis->bestContours.size(); z++) { Scalar dcolor(255,0,0); if (charAnalysis->bestCharSegments[z]) diff --git a/src/openalpr/colorfilter.cpp b/src/openalpr/colorfilter.cpp index 58d042c..1540870 100644 --- a/src/openalpr/colorfilter.cpp +++ b/src/openalpr/colorfilter.cpp @@ -119,7 +119,7 @@ void ColorFilter::findCharColors() vector hMeans, sMeans, vMeans; vector hStdDevs, sStdDevs, vStdDevs; - for (int i = 0; i < contours.size(); i++) + for (uint i = 0; i < contours.size(); i++) { if (hierarchy[i][3] != -1) continue; @@ -372,11 +372,11 @@ int ColorFilter::getMajorityOpinion(vector values, float minPercentAgreem float lowestOverallDiff = 1000000000; int bestPercentAgreementIndex = -1; - for (int i = 0; i < values.size(); i++) + for (uint i = 0; i < values.size(); i++) { int valuesInRange = 0; float overallDiff = 0; - for (int j = 0; j < values.size(); j++) + for (uint j = 0; j < values.size(); j++) { float diff = abs(values[i] - values[j]); if (diff < maxValDifference) diff --git a/src/openalpr/config.h b/src/openalpr/config.h index c41798b..3e0057e 100644 --- a/src/openalpr/config.h +++ b/src/openalpr/config.h @@ -93,9 +93,9 @@ class Config float postProcessMinConfidence; float postProcessConfidenceSkipLevel; - int postProcessMaxSubstitutions; - int postProcessMinCharacters; - int postProcessMaxCharacters; + uint postProcessMaxSubstitutions; + uint postProcessMinCharacters; + uint postProcessMaxCharacters; bool debugGeneral; diff --git a/src/openalpr/detection/detector.cpp b/src/openalpr/detection/detector.cpp index 4837244..3a6fab8 100644 --- a/src/openalpr/detection/detector.cpp +++ b/src/openalpr/detection/detector.cpp @@ -70,17 +70,17 @@ vector Detector::aggregateRegions(vector regions) std::sort(regions.begin(), regions.end(), rectHasLargerArea); // Create new PlateRegions and attach the rectangles to each - for (int i = 0; i < regions.size(); i++) + for (uint i = 0; i < regions.size(); i++) { PlateRegion newRegion; newRegion.rect = regions[i]; orderedRegions.push_back(newRegion); } - for (int i = 0; i < orderedRegions.size(); i++) + for (uint i = 0; i < orderedRegions.size(); i++) { bool foundParent = false; - for (int k = i + 1; k < orderedRegions.size(); k++) + for (uint k = i + 1; k < orderedRegions.size(); k++) { Point center( orderedRegions[i].rect.x + (orderedRegions[i].rect.width / 2), orderedRegions[i].rect.y + (orderedRegions[i].rect.height / 2)); diff --git a/src/openalpr/detection/detectorcpu.cpp b/src/openalpr/detection/detectorcpu.cpp index c63c742..9586551 100644 --- a/src/openalpr/detection/detectorcpu.cpp +++ b/src/openalpr/detection/detectorcpu.cpp @@ -103,7 +103,7 @@ vector DetectorCPU::doCascade(Mat frame, std::vector regi cout << "LBP Time: " << diffclock(startTime, endTime) << "ms." << endl; } - for( int i = 0; i < plates.size(); i++ ) + for( uint i = 0; i < plates.size(); i++ ) { plates[i].x = plates[i].x / scale_factor; plates[i].y = plates[i].y / scale_factor; diff --git a/src/openalpr/featurematcher.cpp b/src/openalpr/featurematcher.cpp index 287c958..8407416 100644 --- a/src/openalpr/featurematcher.cpp +++ b/src/openalpr/featurematcher.cpp @@ -41,7 +41,7 @@ FeatureMatcher::FeatureMatcher(Config* config) FeatureMatcher::~FeatureMatcher() { - for (int i = 0; i < trainingImgKeypoints.size(); i++) + for (uint i = 0; i < trainingImgKeypoints.size(); i++) trainingImgKeypoints[i].clear(); trainingImgKeypoints.clear(); @@ -85,7 +85,7 @@ void FeatureMatcher::_surfStyleMatching(const Mat& queryDescriptors, vector & matches = matchesKnn[descInd]; + //const std::vector & matches = matchesKnn[descInd]; //cout << "two: " << descInd << ":" << matches.size() << endl; // Check to make sure we have 2 matches. I think this is always the case, but it doesn't hurt to be sure @@ -107,7 +107,7 @@ void FeatureMatcher::_surfStyleMatching(const Mat& queryDescriptors, vector queryKeypoints, Rect crissCrossAreaVertical(0, 0, config->stateIdImageWidthPx, config->stateIdimageHeightPx * 2); Rect crissCrossAreaHorizontal(0, 0, config->stateIdImageWidthPx * 2, config->stateIdimageHeightPx); - for (int i = 0; i < billMapping.size(); i++) + for (uint i = 0; i < billMapping.size(); i++) { vector matchesForOnePlate; - for (int j = 0; j < inputMatches.size(); j++) + for (uint j = 0; j < inputMatches.size(); j++) { - if (inputMatches[j].imgIdx == i) + if (inputMatches[j].imgIdx == (int) i) matchesForOnePlate.push_back(inputMatches[j]); } @@ -167,7 +167,7 @@ void FeatureMatcher::crisscrossFiltering(const vector queryKeypoints, vector hlines; vector matchIdx; - for (int j = 0; j < matchesForOnePlate.size(); j++) + for (uint j = 0; j < matchesForOnePlate.size(); j++) { KeyPoint tkp = trainingImgKeypoints[i][matchesForOnePlate[j].trainIdx]; KeyPoint qkp = queryKeypoints[matchesForOnePlate[j].queryIdx]; @@ -184,10 +184,10 @@ void FeatureMatcher::crisscrossFiltering(const vector queryKeypoints, int mostIntersectionsIndex = -1; mostIntersections = 0; - for (int j = 0; j < vlines.size(); j++) + for (uint j = 0; j < vlines.size(); j++) { int intrCount = 0; - for (int q = 0; q < vlines.size(); q++) + for (uint q = 0; q < vlines.size(); q++) { Point vintr = vlines[j].intersection(vlines[q]); Point hintr = hlines[j].intersection(hlines[q]); @@ -221,7 +221,7 @@ void FeatureMatcher::crisscrossFiltering(const vector queryKeypoints, } // Push the non-crisscrosses back on the list - for (int j = 0; j < matchIdx.size(); j++) + for (uint j = 0; j < matchIdx.size(); j++) { outputMatches.push_back(matchesForOnePlate[matchIdx[j]]); } @@ -240,7 +240,7 @@ bool FeatureMatcher::loadRecognitionSet(string country) vector trainImages; vector plateFiles = getFilesInDir(country_dir.c_str()); - for (int i = 0; i < plateFiles.size(); i++) + for (uint i = 0; i < plateFiles.size(); i++) { if (hasEnding(plateFiles[i], ".jpg") == false) continue; @@ -312,12 +312,12 @@ RecognitionResult FeatureMatcher::recognize( const Mat& queryImg, bool drawOnIma // Create and initialize the counts to 0 std::vector bill_match_counts( billMapping.size() ); - for (int i = 0; i < billMapping.size(); i++) + for (uint i = 0; i < billMapping.size(); i++) { bill_match_counts[i] = 0; } - for (int i = 0; i < filteredMatches.size(); i++) + for (uint i = 0; i < filteredMatches.size(); i++) { bill_match_counts[filteredMatches[i].imgIdx]++; //if (filteredMatches[i].imgIdx @@ -326,7 +326,7 @@ RecognitionResult FeatureMatcher::recognize( const Mat& queryImg, bool drawOnIma float max_count = 0; // represented as a percent (0 to 100) int secondmost_count = 0; int maxcount_index = -1; - for (int i = 0; i < billMapping.size(); i++) + for (uint i = 0; i < billMapping.size(); i++) { if (bill_match_counts[i] > max_count && bill_match_counts[i] >= 4) { @@ -354,7 +354,7 @@ RecognitionResult FeatureMatcher::recognize( const Mat& queryImg, bool drawOnIma if (drawOnImage) { vector positiveMatches; - for (int i = 0; i < filteredMatches.size(); i++) + for (uint i = 0; i < filteredMatches.size(); i++) { if (filteredMatches[i].imgIdx == maxcount_index) { @@ -379,7 +379,7 @@ RecognitionResult FeatureMatcher::recognize( const Mat& queryImg, bool drawOnIma if (this->config->debugStateId) { - for (int i = 0; i < billMapping.size(); i++) + for (uint i = 0; i < billMapping.size(); i++) { cout << billMapping[i] << " : " << bill_match_counts[i] << endl; } diff --git a/src/openalpr/licenseplatecandidate.cpp b/src/openalpr/licenseplatecandidate.cpp index 15e998e..8bd30f1 100644 --- a/src/openalpr/licenseplatecandidate.cpp +++ b/src/openalpr/licenseplatecandidate.cpp @@ -83,7 +83,7 @@ void LicensePlateCandidate::recognize() vector LicensePlateCandidate::transformPointsToOriginalImage(Mat bigImage, Mat smallImage, Rect region, vector corners) { vector cornerPoints; - for (int i = 0; i < corners.size(); i++) + for (uint i = 0; i < corners.size(); i++) { float bigX = (corners[i].x * ((float) region.width / smallImage.cols)); float bigY = (corners[i].y * ((float) region.height / smallImage.rows)); diff --git a/src/openalpr/ocr.cpp b/src/openalpr/ocr.cpp index 5c3be9e..3312755 100644 --- a/src/openalpr/ocr.cpp +++ b/src/openalpr/ocr.cpp @@ -63,7 +63,7 @@ void OCR::performOCR(PipelineData* pipeline_data) if (pipeline_data->charRegions.size() < config->postProcessMinCharacters) return; - for (int i = 0; i < pipeline_data->thresholds.size(); i++) + for (uint i = 0; i < pipeline_data->thresholds.size(); i++) { // Make it black text on white background bitwise_not(pipeline_data->thresholds[i], pipeline_data->thresholds[i]); @@ -71,7 +71,7 @@ void OCR::performOCR(PipelineData* pipeline_data) pipeline_data->thresholds[i].size().width, pipeline_data->thresholds[i].size().height, pipeline_data->thresholds[i].channels(), pipeline_data->thresholds[i].step1()); - for (int j = 0; j < pipeline_data->charRegions.size(); j++) + for (uint j = 0; j < pipeline_data->charRegions.size(); j++) { Rect expandedRegion = expandRect( pipeline_data->charRegions[j], 2, 2, pipeline_data->thresholds[i].cols, pipeline_data->thresholds[i].rows) ; diff --git a/src/openalpr/pipeline_data.cpp b/src/openalpr/pipeline_data.cpp index 6aec753..5d7ce38 100644 --- a/src/openalpr/pipeline_data.cpp +++ b/src/openalpr/pipeline_data.cpp @@ -21,7 +21,7 @@ PipelineData::~PipelineData() void PipelineData::clearThresholds() { - for (int i = 0; i < thresholds.size(); i++) + for (uint i = 0; i < thresholds.size(); i++) { thresholds[i].release(); } diff --git a/src/openalpr/platelines.cpp b/src/openalpr/platelines.cpp index a61e23d..eec2447 100644 --- a/src/openalpr/platelines.cpp +++ b/src/openalpr/platelines.cpp @@ -84,9 +84,9 @@ void PlateLines::processImage(Mat inputImage, CharacterRegion* charRegion, float vector hlines = this->getLines(edges, sensitivity, false); vector vlines = this->getLines(edges, sensitivity, true); - for (int i = 0; i < hlines.size(); i++) + for (uint i = 0; i < hlines.size(); i++) this->horizontalLines.push_back(hlines[i]); - for (int i = 0; i < vlines.size(); i++) + for (uint i = 0; i < vlines.size(); i++) this->verticalLines.push_back(vlines[i]); // if debug is enabled, draw the image @@ -227,7 +227,7 @@ Mat PlateLines::customGrayscaleConversion(Mat src) for (int col = 0; col < img_hsv.cols; col++) { int h = (int) img_hsv.at(row, col)[0]; - int s = (int) img_hsv.at(row, col)[1]; + //int s = (int) img_hsv.at(row, col)[1]; int v = (int) img_hsv.at(row, col)[2]; int pixval = pow(v, 1.05); diff --git a/src/openalpr/segmentation/charactersegmenter.cpp b/src/openalpr/segmentation/charactersegmenter.cpp index 62a99fe..52d1127 100644 --- a/src/openalpr/segmentation/charactersegmenter.cpp +++ b/src/openalpr/segmentation/charactersegmenter.cpp @@ -58,7 +58,7 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data) cvtColor(img_contours, img_contours, CV_GRAY2RGB); vector > allowedContours; - for (int i = 0; i < charAnalysis->bestContours.size(); i++) + for (uint i = 0; i < charAnalysis->bestContours.size(); i++) { if (charAnalysis->bestCharSegments[i]) allowedContours.push_back(charAnalysis->bestContours[i]); @@ -92,7 +92,7 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data) vector charWidths; vector charHeights; - for (int i = 0; i < charAnalysis->bestContours.size(); i++) + for (uint i = 0; i < charAnalysis->bestContours.size(); i++) { if (charAnalysis->bestCharSegments[i] == false) continue; @@ -116,7 +116,7 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data) vector allHistograms; vector allBoxes; - for (int i = 0; i < charAnalysis->allContours.size(); i++) + for (uint i = 0; i < charAnalysis->allContours.size(); i++) { Mat histogramMask = Mat::zeros(pipeline_data->thresholds[i].size(), CV_8U); @@ -140,7 +140,7 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data) if (this->config->debugCharSegmenter) { - for (int cboxIdx = 0; cboxIdx < charBoxes.size(); cboxIdx++) + for (uint cboxIdx = 0; cboxIdx < charBoxes.size(); cboxIdx++) { rectangle(allHistograms[i], charBoxes[cboxIdx], Scalar(0, 255, 0)); } @@ -149,7 +149,7 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data) displayImage(config, "Char seg histograms", histDashboard); } - for (int z = 0; z < charBoxes.size(); z++) + for (uint z = 0; z < charBoxes.size(); z++) allBoxes.push_back(charBoxes[z]); //drawAndWait(&histogramMask); } @@ -157,7 +157,7 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data) float medianCharWidth = avgCharWidth; vector widthValues; // Compute largest char width - for (int i = 0; i < allBoxes.size(); i++) + for (uint i = 0; i < allBoxes.size(); i++) { widthValues.push_back(allBoxes[i].width); } @@ -177,7 +177,7 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data) if (this->config->debugCharSegmenter) { // Setup the dashboard images to show the cleaning filters - for (int i = 0; i < pipeline_data->thresholds.size(); i++) + for (uint i = 0; i < pipeline_data->thresholds.size(); i++) { Mat cleanImg = Mat::zeros(pipeline_data->thresholds[i].size(), pipeline_data->thresholds[i].type()); Mat boxMask = getCharBoxMask(pipeline_data->thresholds[i], candidateBoxes); @@ -185,7 +185,7 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data) bitwise_and(cleanImg, boxMask, cleanImg); cvtColor(cleanImg, cleanImg, CV_GRAY2BGR); - for (int c = 0; c < candidateBoxes.size(); c++) + for (uint c = 0; c < candidateBoxes.size(); c++) rectangle(cleanImg, candidateBoxes[c], Scalar(0, 255, 0), 1); imgDbgCleanStages.push_back(cleanImg); } @@ -255,7 +255,7 @@ vector CharacterSegmenter::getHistogramBoxes(VerticalHistogram histogram, vector charBoxes; vector allBoxes = get1DHits(histogram.histoImg, pxLeniency); - for (int i = 0; i < allBoxes.size(); i++) + for (uint i = 0; i < allBoxes.size(); i++) { if (allBoxes[i].width >= config->segmentationMinBoxWidthPx && allBoxes[i].width <= MAX_SEGMENT_WIDTH && allBoxes[i].height > MIN_HISTOGRAM_HEIGHT ) @@ -311,7 +311,7 @@ vector CharacterSegmenter::getBestCharBoxes(Mat img, vector charBoxe { columnCount = 0; - for (int i = 0; i < charBoxes.size(); i++) + for (uint i = 0; i < charBoxes.size(); i++) { if (col >= charBoxes[i].x && col < (charBoxes[i].x + charBoxes[i].width)) columnCount++; @@ -343,7 +343,7 @@ vector CharacterSegmenter::getBestCharBoxes(Mat img, vector charBoxe float rowScore = 0; - for (int boxidx = 0; boxidx < allBoxes.size(); boxidx++) + for (uint boxidx = 0; boxidx < allBoxes.size(); boxidx++) { int w = allBoxes[boxidx].width; if (w >= config->segmentationMinBoxWidthPx && w <= MAX_SEGMENT_WIDTH) @@ -402,7 +402,7 @@ vector CharacterSegmenter::getBestCharBoxes(Mat img, vector charBoxe Mat imgBestBoxes(img.size(), img.type()); img.copyTo(imgBestBoxes); cvtColor(imgBestBoxes, imgBestBoxes, CV_GRAY2BGR); - for (int i = 0; i < bestBoxes.size(); i++) + for (uint i = 0; i < bestBoxes.size(); i++) rectangle(imgBestBoxes, bestBoxes[i], Scalar(0, 255, 0)); this->imgDbgGeneral.push_back(addLabel(histoImg, "All Histograms")); @@ -448,9 +448,9 @@ void CharacterSegmenter::removeSmallContours(vector thresholds, vector CharacterSegmenter::combineCloseBoxes( vector charBoxes, floa { vector newCharBoxes; - for (int i = 0; i < charBoxes.size(); i++) + for (uint i = 0; i < charBoxes.size(); i++) { if (i == charBoxes.size() - 1) { @@ -490,7 +490,7 @@ vector CharacterSegmenter::combineCloseBoxes( vector charBoxes, floa newCharBoxes.push_back(bigRect); if (this->config->debugCharSegmenter) { - for (int z = 0; z < pipeline_data->thresholds.size(); z++) + for (uint z = 0; z < pipeline_data->thresholds.size(); z++) { Point center(bigRect.x + bigRect.width / 2, bigRect.y + bigRect.height / 2); RotatedRect rrect(center, Size2f(bigRect.width, bigRect.height + (bigRect.height / 2)), 0); @@ -519,7 +519,7 @@ void CharacterSegmenter::cleanCharRegions(vector thresholds, vector c Mat mask = getCharBoxMask(thresholds[0], charRegions); - for (int i = 0; i < thresholds.size(); i++) + for (uint i = 0; i < thresholds.size(); i++) { bitwise_and(thresholds[i], mask, thresholds[i]); vector > contours; @@ -536,14 +536,14 @@ void CharacterSegmenter::cleanCharRegions(vector thresholds, vector c findContours(tempImg, contours, RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); - for (int j = 0; j < charRegions.size(); j++) + for (uint j = 0; j < charRegions.size(); j++) { const float MIN_SPECKLE_HEIGHT = ((float)charRegions[j].height) * MIN_SPECKLE_HEIGHT_PERCENT; const float MIN_CONTOUR_AREA = ((float)charRegions[j].area()) * MIN_CONTOUR_AREA_PERCENT; int tallestContourHeight = 0; float totalArea = 0; - for (int c = 0; c < contours.size(); c++) + for (uint c = 0; c < contours.size(); c++) { if (contours[c].size() == 0) continue; @@ -615,7 +615,7 @@ void CharacterSegmenter::cleanCharRegions(vector thresholds, vector c morphologyEx(thresholds[i], thresholds[i], MORPH_CLOSE, closureElement); // Lastly, draw a clipping line between each character boxes - for (int j = 0; j < charRegions.size(); j++) + for (uint j = 0; j < charRegions.size(); j++) { line(thresholds[i], Point(charRegions[j].x - 1, charRegions[j].y), Point(charRegions[j].x - 1, charRegions[j].y + charRegions[j].height), Scalar(0, 0, 0)); line(thresholds[i], Point(charRegions[j].x + charRegions[j].width + 1, charRegions[j].y), Point(charRegions[j].x + charRegions[j].width + 1, charRegions[j].y + charRegions[j].height), Scalar(0, 0, 0)); @@ -629,9 +629,9 @@ void CharacterSegmenter::cleanBasedOnColor(vector thresholds, Mat colorMask // Consider it a bad news bear. REmove the whole area. const float MIN_PERCENT_CHUNK_REMOVED = 0.6; - for (int i = 0; i < thresholds.size(); i++) + for (uint i = 0; i < thresholds.size(); i++) { - for (int j = 0; j < charRegions.size(); j++) + for (uint j = 0; j < charRegions.size(); j++) { Mat boxChar = Mat::zeros(thresholds[i].size(), CV_8U); rectangle(boxChar, charRegions[j], Scalar(255,255,255), CV_FILLED); @@ -679,12 +679,12 @@ void CharacterSegmenter::cleanMostlyFullBoxes(vector thresholds, const vect { float MAX_FILLED = 0.95 * 255; - for (int i = 0; i < charRegions.size(); i++) + for (uint i = 0; i < charRegions.size(); i++) { Mat mask = Mat::zeros(thresholds[0].size(), CV_8U); rectangle(mask, charRegions[i], Scalar(255,255,255), -1); - for (int j = 0; j < thresholds.size(); j++) + for (uint j = 0; j < thresholds.size(); j++) { if (mean(thresholds[j], mask)[0] > MAX_FILLED) { @@ -713,12 +713,12 @@ vector CharacterSegmenter::filterMostlyEmptyBoxes(vector thresholds, vector boxScores(charRegions.size()); - for (int i = 0; i < charRegions.size(); i++) + for (uint i = 0; i < charRegions.size(); i++) boxScores[i] = 0; - for (int i = 0; i < thresholds.size(); i++) + for (uint i = 0; i < thresholds.size(); i++) { - for (int j = 0; j < charRegions.size(); j++) + for (uint j = 0; j < charRegions.size(); j++) { //float minArea = charRegions[j].area() * MIN_AREA_PERCENT; @@ -729,15 +729,13 @@ vector CharacterSegmenter::filterMostlyEmptyBoxes(vector thresholds, vector > contours; findContours(tempImg, contours, RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); - float biggestContourHeight = 0; - vector allPointsInBox; - for (int c = 0; c < contours.size(); c++) + for (uint c = 0; c < contours.size(); c++) { if (contours[c].size() == 0) continue; - for (int z = 0; z < contours[c].size(); z++) + for (uint z = 0; z < contours[c].size(); z++) allPointsInBox.push_back(contours[c][z]); } @@ -761,7 +759,7 @@ vector CharacterSegmenter::filterMostlyEmptyBoxes(vector thresholds, vector newCharRegions; int maxBoxScore = 0; - for (int i = 0; i < charRegions.size(); i++) + for (uint i = 0; i < charRegions.size(); i++) { if (boxScores[i] > maxBoxScore) maxBoxScore = boxScores[i]; @@ -771,7 +769,7 @@ vector CharacterSegmenter::filterMostlyEmptyBoxes(vector thresholds, int MIN_FULL_BOXES = maxBoxScore * 0.49; // Now check each score. If it's below the minimum, remove the charRegion - for (int i = 0; i < charRegions.size(); i++) + for (uint i = 0; i < charRegions.size(); i++) { if (boxScores[i] > MIN_FULL_BOXES) newCharRegions.push_back(charRegions[i]); @@ -784,7 +782,7 @@ vector CharacterSegmenter::filterMostlyEmptyBoxes(vector thresholds, cout << " this box had a score of : " << boxScores[i];; cout << " MIN_FULL_BOXES: " << MIN_FULL_BOXES << endl;; - for (int z = 0; z < thresholds.size(); z++) + for (uint z = 0; z < thresholds.size(); z++) { rectangle(thresholds[z], charRegions[i], Scalar(0,0,0), -1); @@ -834,7 +832,7 @@ void CharacterSegmenter::filterEdgeBoxes(vector thresholds, const vector leftEdges; vector rightEdges; - for (int i = 0; i < thresholds.size(); i++) + for (uint i = 0; i < thresholds.size(); i++) { Mat rotated; @@ -940,7 +938,7 @@ void CharacterSegmenter::filterEdgeBoxes(vector thresholds, const vector thresholds, const vector tallestContourHeight) @@ -1134,7 +1132,7 @@ int CharacterSegmenter::isSkinnyLineInsideBox(Mat threshold, Rect box, vector charBoxes) { Mat mask = Mat::zeros(img_threshold.size(), CV_8U); - for (int i = 0; i < charBoxes.size(); i++) + for (uint i = 0; i < charBoxes.size(); i++) rectangle(mask, charBoxes[i], Scalar(255, 255, 255), -1); return mask; diff --git a/src/openalpr/segmentation/verticalhistogram.cpp b/src/openalpr/segmentation/verticalhistogram.cpp index d4adcad..88b506b 100644 --- a/src/openalpr/segmentation/verticalhistogram.cpp +++ b/src/openalpr/segmentation/verticalhistogram.cpp @@ -105,7 +105,7 @@ int VerticalHistogram::getHeightAt(int x) void VerticalHistogram::findValleys() { - int MINIMUM_PEAK_HEIGHT = (int) (((float) highestPeak) * 0.75); + //int MINIMUM_PEAK_HEIGHT = (int) (((float) highestPeak) * 0.75); int totalWidth = colHeights.size(); @@ -114,7 +114,7 @@ void VerticalHistogram::findValleys() HistogramDirection prevDirection = FALLING; int relativePeakHeight = 0; - int valleyStart = 0; + //int valleyStart = 0; for (int i = 0; i < totalWidth; i++) { @@ -143,7 +143,7 @@ void VerticalHistogram::findValleys() } } -HistogramDirection VerticalHistogram::getHistogramDirection(int index) +HistogramDirection VerticalHistogram::getHistogramDirection(uint index) { int EXTRA_WIDTH_TO_AVERAGE = 2; @@ -153,7 +153,7 @@ HistogramDirection VerticalHistogram::getHistogramDirection(int index) int trailStartIndex = index - EXTRA_WIDTH_TO_AVERAGE; if (trailStartIndex < 0) trailStartIndex = 0; - int forwardEndIndex = index + EXTRA_WIDTH_TO_AVERAGE; + uint forwardEndIndex = index + EXTRA_WIDTH_TO_AVERAGE; if (forwardEndIndex >= colHeights.size()) forwardEndIndex = colHeights.size() - 1; @@ -163,7 +163,7 @@ HistogramDirection VerticalHistogram::getHistogramDirection(int index) } trailingAverage = trailingAverage / ((float) (1 + index - trailStartIndex)); - for (int i = index; i <= forwardEndIndex; i++) + for (uint i = index; i <= forwardEndIndex; i++) { forwardAverage += colHeights[i]; } diff --git a/src/openalpr/segmentation/verticalhistogram.h b/src/openalpr/segmentation/verticalhistogram.h index 3716152..56f5cb9 100644 --- a/src/openalpr/segmentation/verticalhistogram.h +++ b/src/openalpr/segmentation/verticalhistogram.h @@ -58,7 +58,7 @@ class VerticalHistogram void analyzeImage(cv::Mat inputImage, cv::Mat mask); void findValleys(); - HistogramDirection getHistogramDirection(int index); + HistogramDirection getHistogramDirection(uint index); }; #endif // OPENALPR_VERTICALHISTOGRAM_H diff --git a/src/openalpr/utility.cpp b/src/openalpr/utility.cpp index 914fdea..4e13daf 100644 --- a/src/openalpr/utility.cpp +++ b/src/openalpr/utility.cpp @@ -45,13 +45,13 @@ Rect expandRect(Rect original, int expandXPixels, int expandYPixels, int maxX, i return expandedRegion; } -Mat drawImageDashboard(vector images, int imageType, int numColumns) +Mat drawImageDashboard(vector images, int imageType, uint numColumns) { - int numRows = ceil((float) images.size() / (float) numColumns); + uint numRows = ceil((float) images.size() / (float) numColumns); Mat dashboard(Size(images[0].cols * numColumns, images[0].rows * numRows), imageType); - for (int i = 0; i < numColumns * numRows; i++) + for (uint i = 0; i < numColumns * numRows; i++) { if (i < images.size()) images[i].copyTo(dashboard(Rect((i%numColumns) * images[i].cols, floor((float) i/numColumns) * images[i].rows, images[i].cols, images[i].rows))); @@ -386,6 +386,10 @@ std::string toString(int value) ss << value; return ss.str(); } +std::string toString(uint value) +{ + return toString((int) value); +} std::string toString(float value) { stringstream ss; diff --git a/src/openalpr/utility.h b/src/openalpr/utility.h index d71a708..0262acc 100644 --- a/src/openalpr/utility.h +++ b/src/openalpr/utility.h @@ -84,7 +84,7 @@ double median(int array[], int arraySize); std::vector produceThresholds(const cv::Mat img_gray, Config* config); -cv::Mat drawImageDashboard(std::vector images, int imageType, int numColumns); +cv::Mat drawImageDashboard(std::vector images, int imageType, uint numColumns); void displayImage(Config* config, std::string windowName, cv::Mat frame); void drawAndWait(cv::Mat* frame); @@ -108,6 +108,7 @@ cv::Mat addLabel(cv::Mat input, std::string label); std::string toString(int value); +std::string toString(uint value); std::string toString(float value); std::string toString(double value);