aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormutantturkey <mutantturke@gmail.com>2012-08-03 14:34:17 -0400
committermutantturkey <mutantturke@gmail.com>2012-08-03 14:34:17 -0400
commitaaffa57083d35349a573dd03e5f5f905da2b69d9 (patch)
tree1cc1b3458ec1fc2ac2708c4e4e402273485b0a23
parent23c7f8836f50b9d31bea9dbe988f0d449179fe3c (diff)
inital commit of the FlyTrackingMain rewrite utilizng the OpenCV and CvBlob libraries
-rw-r--r--fly-tools/fly-tracker/main.cpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/fly-tools/fly-tracker/main.cpp b/fly-tools/fly-tracker/main.cpp
new file mode 100644
index 0000000..dab81b3
--- /dev/null
+++ b/fly-tools/fly-tracker/main.cpp
@@ -0,0 +1,127 @@
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <opencv/cv.h>
+#include <opencv/highgui.h>
+#include <cvblob.h>
+
+using namespace std;
+using namespace cvb;
+
+ofstream nullLog;
+ostream* output;
+
+bool cmpArea(const pair<CvLabel, CvBlob*> &p1, const pair<CvLabel, CvBlob*> &p2)
+{
+ return p1.second->area < p2.second->area;
+}
+
+int main(int argc, char* argv[]) {
+
+ int c;
+
+ bool verbose = false;
+
+ string usage = "fly-tracker -i <input-list> -o <output-folder> -t <type> -n <number>";
+
+ string inputFileName;
+ string outputFolderName;
+
+ int setNumber;
+ bool setNumberSet;
+ string setType;
+
+ CvBlobs blobs;
+ CvBlobs largeBlobs;
+
+ IplImage *inputImg;
+ IplImage *outputImg;
+ IplImage *labelImg;
+
+ vector< pair<CvLabel, CvBlob*> > blobList;
+
+ while ((c = getopt (argc, argv, "i:o:t:n:hv")) != -1)
+ switch (c) {
+ case 'i':
+ inputFileName = optarg;
+ break;
+ case 'o':
+ outputFolderName = optarg;
+ break;
+ case 'v':
+ verbose = true;
+ break;
+ case 't':
+ setType = optarg;
+ break;
+ case 'n':
+ setNumberSet = true;
+ setNumber = atoi(optarg);
+ break;
+ case 'h':
+ cout << usage << endl;
+ exit(EXIT_SUCCESS);
+ break;
+ default:
+ break;
+ }
+
+ if ( inputFileName.empty() || outputFolderName.empty() || !setNumberSet || setType.empty() ) {
+ cerr << usage << endl;
+ exit(EXIT_FAILURE);
+ }
+
+ (verbose) ? output = &cout : output = &nullLog;
+
+ *output << "Verbose logging enabled" << endl;
+
+ // read input file
+
+ ifstream inputFile(inputFileName.c_str());
+
+ if (inputFile.fail() ) {
+ cerr << "cannot open the input file that contains name of the input images\n";
+ exit(EXIT_FAILURE);
+ }
+
+ string fileName;
+ int fileNumber;
+ bool togetherState = false;
+
+ while (inputFile>>fileName) {
+
+ IplImage *inputImg, *outputImg, *labelImg;
+ inputImg = cvLoadImage(fileName.c_str(), CV_LOAD_IMAGE_GRAYSCALE);
+
+ CvBlobs blobs;
+
+ vector< pair<CvLabel, CvBlob*> > blobList;
+
+ // label blobs
+ labelImg = cvCreateImage(cvGetSize(inputImg),IPL_DEPTH_LABEL,1);
+
+ cvLabel(inputImg, labelImg, blobs);
+
+ // copy and sort blobs
+ copy(blobs.begin(), blobs.end(), back_inserter(blobList));
+ sort(blobList.begin(), blobList.end(), cmpArea);
+
+ (blobList.size() == 1) ? togetherState = true : togetherState = false;
+
+ // List detected blob in each file
+ *output << "File: " << fileName << endl;
+ *output << "\t Together:" << togetherState << endl;
+ for (int i=0; i<(int)blobList.size(); i++) {
+ *output << "\t Blob #" << blobList[i].first << " -> " << (*blobList[i].second) << endl;
+ }
+
+
+ // Release all the memory
+ cvReleaseImage(&labelImg);
+ cvReleaseImage(&inputImg);
+ cvReleaseBlobs(blobs);
+
+ }
+
+ return 0;
+}