Fixed compiler warnings (signed/unsigned comparisons, unused variables)

This commit is contained in:
Matt Hill
2014-08-28 21:57:10 -04:00
parent 5903e5fb8c
commit 1801733061
19 changed files with 133 additions and 131 deletions

View File

@@ -58,7 +58,7 @@ CharacterSegmenter::CharacterSegmenter(PipelineData* pipeline_data)
cvtColor(img_contours, img_contours, CV_GRAY2RGB);
vector<vector<Point> > 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<int> charWidths;
vector<int> 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<Mat> allHistograms;
vector<Rect> 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<int> 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<Rect> CharacterSegmenter::getHistogramBoxes(VerticalHistogram histogram,
vector<Rect> charBoxes;
vector<Rect> 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<Rect> CharacterSegmenter::getBestCharBoxes(Mat img, vector<Rect> 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<Rect> CharacterSegmenter::getBestCharBoxes(Mat img, vector<Rect> 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<Rect> CharacterSegmenter::getBestCharBoxes(Mat img, vector<Rect> 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<Mat> thresholds, vector<vect
//const float MIN_CHAR_AREA = 0.02 * avgCharWidth * avgCharHeight; // To clear out the tiny specks
const float MIN_CONTOUR_HEIGHT = 0.3 * avgCharHeight;
for (int i = 0; i < thresholds.size(); i++)
for (uint i = 0; i < thresholds.size(); i++)
{
for (int c = 0; c < allContours[i].size(); c++)
for (uint c = 0; c < allContours[i].size(); c++)
{
if (allContours[i][c].size() == 0)
continue;
@@ -470,7 +470,7 @@ vector<Rect> CharacterSegmenter::combineCloseBoxes( vector<Rect> charBoxes, floa
{
vector<Rect> 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<Rect> CharacterSegmenter::combineCloseBoxes( vector<Rect> 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<Mat> thresholds, vector<Rect> 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<vector<Point> > contours;
@@ -536,14 +536,14 @@ void CharacterSegmenter::cleanCharRegions(vector<Mat> thresholds, vector<Rect> 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<Mat> thresholds, vector<Rect> 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<Mat> 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<Mat> 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<Rect> CharacterSegmenter::filterMostlyEmptyBoxes(vector<Mat> thresholds,
vector<int> 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<Rect> CharacterSegmenter::filterMostlyEmptyBoxes(vector<Mat> thresholds,
vector<vector<Point> > contours;
findContours(tempImg, contours, RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
float biggestContourHeight = 0;
vector<Point> 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<Rect> CharacterSegmenter::filterMostlyEmptyBoxes(vector<Mat> thresholds,
vector<Rect> 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<Rect> CharacterSegmenter::filterMostlyEmptyBoxes(vector<Mat> 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<Rect> CharacterSegmenter::filterMostlyEmptyBoxes(vector<Mat> 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<Mat> thresholds, const vector<Re
vector<int> leftEdges;
vector<int> 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<Mat> thresholds, const vector<Re
cout << "Edge Filter: Entire right region is erased" << endl;
}
for (int i = 0; i < thresholds.size(); i++)
for (uint i = 0; i < thresholds.size(); i++)
{
bitwise_and(thresholds[i], mask, thresholds[i]);
}
@@ -953,7 +951,7 @@ void CharacterSegmenter::filterEdgeBoxes(vector<Mat> thresholds, const vector<Re
Mat invertedMask(mask.size(), mask.type());
bitwise_not(mask, invertedMask);
for (int z = 0; z < imgDbgCleanStages.size(); z++)
for (uint z = 0; z < imgDbgCleanStages.size(); z++)
fillMask(imgDbgCleanStages[z], invertedMask, Scalar(0,0,255));
}
}
@@ -1087,7 +1085,7 @@ int CharacterSegmenter::isSkinnyLineInsideBox(Mat threshold, Rect box, vector<ve
Mat boxMask = Mat::zeros(threshold.size(), CV_8U);
rectangle(boxMask, slightlySmallerBox, Scalar(255, 255, 255), -1);
for (int i = 0; i < contours.size(); i++)
for (uint i = 0; i < contours.size(); i++)
{
// Only bother with the big boxes
if (boundingRect(contours[i]).height < MIN_EDGE_CONTOUR_HEIGHT)
@@ -1103,7 +1101,7 @@ int CharacterSegmenter::isSkinnyLineInsideBox(Mat threshold, Rect box, vector<ve
int tallestContourHeight = 0;
int tallestContourWidth = 0;
float tallestContourArea = 0;
for (int s = 0; s < subContours.size(); s++)
for (uint s = 0; s < subContours.size(); s++)
{
Rect r = boundingRect(subContours[s]);
if (r.height > tallestContourHeight)
@@ -1134,7 +1132,7 @@ int CharacterSegmenter::isSkinnyLineInsideBox(Mat threshold, Rect box, vector<ve
Mat CharacterSegmenter::getCharBoxMask(Mat img_threshold, vector<Rect> 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;