From 230c1ed46fdc851239647731cddd9a3dc3634fa9 Mon Sep 17 00:00:00 2001 From: mutantturkey Date: Thu, 2 Aug 2012 19:15:10 -0400 Subject: employ logging system, fixup output to be more consistent, get rid of returned result --- fly-tools/filter/main.cpp | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'fly-tools/filter') diff --git a/fly-tools/filter/main.cpp b/fly-tools/filter/main.cpp index ec7899f..4f78650 100644 --- a/fly-tools/filter/main.cpp +++ b/fly-tools/filter/main.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include #include #include @@ -6,6 +8,9 @@ using namespace std; using namespace cvb; +ofstream nullLog; +ostream* output; + bool cmpArea(const pair &p1, const pair &p2) { return p1.second->area < p2.second->area; @@ -16,13 +21,13 @@ int main(int argc, char* argv[]) { int c; int drawNumber = 2; - double ratio; - - unsigned int result; + double ratio = 0; - bool ratioSet; + bool verbose = false; + bool ratioSet = false; string usage = "filter-mask -i -o -r "; + string inputFileName; string outputFileName; @@ -36,7 +41,7 @@ int main(int argc, char* argv[]) { vector< pair > blobList; - while ((c = getopt (argc, argv, "i:o:r:h")) != -1) + while ((c = getopt (argc, argv, "i:o:r:hv")) != -1) switch (c) { case 'i': inputFileName = optarg; @@ -44,6 +49,9 @@ int main(int argc, char* argv[]) { case 'o': outputFileName = optarg; break; + case 'v': + verbose = true; + break; case 'r': ratioSet = true; ratio = atoi(optarg); @@ -61,15 +69,25 @@ int main(int argc, char* argv[]) { exit(1); } + if(verbose) { + output = &cout; + } else { + output = &nullLog; + } + + *output << "Verbose logging enabled" << endl; + + // read input file img = cvLoadImage(inputFileName.c_str(), 1); - imgOut = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); cvZero(imgOut); + imgOut = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); cvZero(imgOut); grey = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); cvCvtColor(img, grey, CV_BGR2GRAY); + // label blobs labelImg = cvCreateImage(cvGetSize(grey),IPL_DEPTH_LABEL,1); - result = cvLabel(grey, labelImg, blobs); + cvLabel(grey, labelImg, blobs); // copy and sort blobs copy(blobs.begin(), blobs.end(), back_inserter(blobList)); @@ -77,26 +95,26 @@ int main(int argc, char* argv[]) { // if no blobs. if(blobList.size() == 0) { - cerr << "No blobs found." << endl; + cerr << "No blobs found" << endl; cvSaveImage(outputFileName.c_str(), imgOut); exit(1); } // if only one blob is detected. if(blobList.size() == 1 ) { - cout << "Only one blob found!" << endl; + *output << "Only one blob found" << endl; drawNumber = 1; } // if the ratio of the of the two blobs is smaller than the input ratio. if( ((double)blobList[blobList.size()-drawNumber].second->area / (double)blobList[blobList.size()-1].second->area) < (1/ratio) ) { - cout << "the second largest blob is smaller than the ratio. only drawing largest blob!" << endl; + *output << "the second largest blob is smaller than the ratio. only drawing largest blob" << endl; drawNumber = 1; } - for (int i=blobList.size()-drawNumber; i " << (*blobList[i].second) << endl; + *output << "Blob #" << blobList[i].first << " -> " << (*blobList[i].second) << endl; } // draw the selected blobsto imgOut and write the image. -- cgit v1.2.3