Commits

iorodeo committed 678378b

Cleaned up a bit more. Added toStdString and print methods to SegementData, PositonData and GenderData types.

  • Participants
  • Parent commits 045b6b2

Comments (0)

Files changed (9)

File src/demo/fly_sorter/fly_segmenter.cpp

 #include "fly_segmenter.hpp"
 #include <iostream>
+#include <sstream>
 #include <opencv2/core/core.hpp>
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
 #include "bgr_to_luv_converter.hpp"
 
 
+// SegmentData
+// ----------------------------------------------------------------------------
+SegmentData::SegmentData() {};
+
+std::string SegmentData::toStdString(unsigned int indent)
+{
+    std::stringstream ss;
+    std::string indentStr0 = getIndentString(indent);
+    std::string indentStr1 = getIndentString(indent+1);
+    ss << indentStr0 << "SegmentData:" << std::endl;
+    ss << indentStr1 << "predictorData: (not shown)" << std::endl;
+    ss << indentStr1 << "boundingImageLUV: (not shown)" << std::endl;
+    ss << blobData.toStdString(indent+1);
+    return ss.str();
+}
+
+
+void SegmentData::print(unsigned int indent)
+{
+    std::cout << toStdString(indent);
+}
+
+
 // FlySegmenter
 // ----------------------------------------------------------------------------
 FlySegmenter::FlySegmenter() {}

File src/demo/fly_sorter/fly_segmenter.hpp

 #include "blob_finder.hpp"
 #include "fast_binary_predictor.hpp"
 #include <list>
+#include <string>
 
 
 class SegmentData 
 {
     public:
-        SegmentData() {};
         FastBinaryPredictorData<cv::Mat> predictorData;
         cv::Mat boundingImageLUV;
         BlobData blobData;
+
+        SegmentData();
+        std::string toStdString(unsigned int indent=0);
+        void print(unsigned int indent=0);
 };
 typedef std::list<SegmentData> SegmentDataList;
 

File src/demo/fly_sorter/fly_sorter_window.cpp

 {
     if (running_)
     {
-        std::cout << imageData.frameCount << std::endl;
 
         imageData_.copy(imageData);
         blobFinderData_ = blobFinder_.findBlobs(imageData_.mat);
         flySegmenterData_ = flySegmenter_.segment(blobFinderData_);
         hogPositionFitterData_ = hogPositionFitter_.fit(flySegmenterData_,imageData.frameCount,imageData.mat);
         genderSorterData_ = genderSorter_.sort(hogPositionFitterData_);
-
-
-        //// DEBUG
-        //// ----------------------------------------------------------------------
-        //BlobDataList::iterator it;
-        //for (it=blobFinderData_.blobDataList.begin(); it!=blobFinderData_.blobDataList.end(); it++)
-        //{
-        //    BlobData data = *it;
-        //    std::cout << "onX:      " << data.onBorderX << std::endl;
-        //    std::cout << "onY:      " << data.onBorderY << std::endl;
-        //    std::cout << "x0, x1:   " << data.boundingRect.x << ", " << (data.boundingRect.x + data.boundingRect.width) << std::endl;
-        //    std::cout << "y0, y1:   " << data.boundingRect.y << ", " << (data.boundingRect.y + data.boundingRect.height) << std::endl;
-        //    std::cout << "cols:     " << imageData_.mat.cols << std::endl;
-        //    std::cout << "rows:     " << imageData_.mat.rows << std::endl;
-        //    std::cout << std::endl;
-        //}
-        //// ----------------------------------------------------------------------
-
-
-        // DEBUG
-        // -----------------------------------------------------------------------
-
-        //debugStream << "Frame Count: " << imageData.frameCount << std::endl;
-        //if (hogPositionFitterData_.positionDataList.empty())
-        //{
-        //    debugStream << "  " << "PositionData: None"  << std::endl;
-        //}
-        //else
-        //{
-        //    debugStream << "  " << "PositionData: "  << std::endl;
-
-        //    PositionDataList::iterator it;
-        //    unsigned int count;
-        //    for (
-        //            it  = hogPositionFitterData_.positionDataList.begin(), count=0;
-        //            it != hogPositionFitterData_.positionDataList.end();
-        //            it++, count++
-        //        )
-        //    {
-        //        PositionData posData = *it;
-        //        debugStream << std::endl;
-        //        debugStream << "    " << "count:            " << count << std::endl;
-        //        debugStream << "    " << "success:          " << posData.success << std::endl;
-        //        debugStream << "    " << "isFly:            " << posData.isFly << std::endl; 
-        //        debugStream << "    " << "isMultipleFlies:  " << posData.isMultipleFlies << std::endl;
-        //        debugStream << "    " << "bodyArea:         " << posData.bodyArea << std::endl;
-        //        debugStream << std::endl;
-        //    }
-        //}
-
-        // Write images to file
-        // ----------------------------------------------------------------------
-        //QString imgFileName = QString("image_%1.bmp").arg(imageData.frameCount);
-        //cv::imwrite(imgFileName.toStdString(),imageData.mat);
-        // ----------------------------------------------------------------------
-
-
         if ((httpOutputCheckBoxPtr_ -> checkState()) == Qt::Checked)
         {
             sendDataViaHttpRequest();
         }
+
+        // DEBUG - display gender data
+        // -------------------------------------------------------------------------
+        if (0)
+        {
+            std::cout << "Frame Count: " << imageData.frameCount << std::endl;
+            GenderDataList genderDataList = genderSorterData_.genderDataList;
+            GenderDataList::iterator it;
+
+            for (it=genderDataList.begin(); it!=genderDataList.end(); it++)
+            {
+                GenderData data = *it;
+                std::cout << data.toStdString(1) << std::endl;
+            }
+        }
+        // -------------------------------------------------------------------------
+
+
+        // DEBUG - write images to file
+        // -------------------------------------------------------------------------
+        if (0)
+        {
+            QString imgFileName = QString("image_%1.bmp").arg(imageData.frameCount);
+            cv::imwrite(imgFileName.toStdString(),imageData.mat);
+        }
+        // -------------------------------------------------------------------------
+
     }
 }
 

File src/demo/fly_sorter/gender_sorter.cpp

 #include "gender_sorter.hpp"
 #include <cmath>
+#include <sstream>
 #include <iostream>
 
 // GenderData
 };
 
 
+std::string GenderData::toStdString(unsigned int indent)
+{
+    std::stringstream ss;
+    std::string indentStr0 = getIndentString(indent);
+    std::string indentStr1 = getIndentString(indent+1);
+    std::string indentStr2 = getIndentString(indent+2);
+    std::string genderStr = GenderSorter::GenderToString(gender);
+    ss << indentStr0 << "GenderData: " << std::endl;
+    ss << indentStr1 << "gender: " << genderStr << std::endl; 
+    ss << indentStr1 << "havePredictorData: " << havePredictorData << std::endl;
+    ss << indentStr1 << "predictorData: " << std::endl;
+    if (havePredictorData)
+    {
+        ss << indentStr2 << "labal: " << predictorData.label << std::endl;
+        ss << indentStr2 << "fit: " << predictorData.fit << std::endl;
+    }
+    ss << positionData.toStdString(indent+1);
+    return ss.str();
+}
+
+
+void GenderData::print(unsigned int indent)
+{
+    std::cout << toStdString(indent);
+}
+
+
 // GenderSorter
 // ----------------------------------------------------------------------------
 GenderSorter::GenderSorter() {};

File src/demo/fly_sorter/gender_sorter.hpp

 #include "fast_binary_predictor.hpp"
 #include "hog_position_fitter.hpp"
 #include <list>
+#include <string>
 
 enum Gender 
 {
         bool havePredictorData;
         FastBinaryPredictorData<double> predictorData;
         GenderData();
+        std::string toStdString(unsigned int indent=0);
+        void print(unsigned int indent=0);
 };
 typedef std::list<GenderData> GenderDataList;
 

File src/demo/fly_sorter/hog_position_fitter.cpp

 #define _USE_MATH_DEFINES
 #include <cmath>
 #include <cfloat>
+#include <sstream>
 #include <iostream>
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
     covarianceMatrix = cv::Mat(2,2,CV_64FC1,cv::Scalar(0.0));
 }
 
+
+std::string PositionData::toStdString(unsigned int indent)
+{
+    std::stringstream ss;
+    std::string indentStr0 = getIndentString(indent);
+    std::string indentStr1 = getIndentString(indent+1);
+    std::string indentStr2 = getIndentString(indent+2);
+    ss << indentStr0 << "PositionData:" << std::endl;
+    ss << indentStr1 << "success: " << success << std::endl;
+    ss << indentStr1 << "isFly: " << isFly << std::endl;
+    ss << indentStr1 << "flipped: " << flipped << std::endl;
+    ss << indentStr1 << "bodyArea: " << bodyArea << std::endl;
+    ss << indentStr1 << "meanXRel: " << meanXRel << std::endl;
+    ss << indentStr1 << "meanYRel: " << meanYRel << std::endl;
+    ss << indentStr1 << "meanXAbs: " << meanXAbs << std::endl;
+    ss << indentStr1 << "meanYAbs: " << meanYAbs << std::endl;
+    ss << indentStr1 << "ellipseMajorAxis: " << ellipseMajorAxis << std::endl;
+    ss << indentStr1 << "ellipseMinorAxis: " << ellipseMinorAxis << std::endl;
+    ss << indentStr1 << "ellipseAngle: " << ellipseAngle << std::endl;
+    ss << indentStr1 << "covarianceMatrix: " << std::endl;
+    for (int i=0; i<2; i++)
+    {
+        ss << indentStr2; 
+        for (int j=0; j<2; j++)
+        {
+            ss << covarianceMatrix.at<double>(i,j) << " ";
+        }
+        ss << std::endl;
+    }
+    ss << indentStr1 << "rotBoundingImageLUV: (not shown)" << std::endl;
+    ss << indentStr1 << "pixelFeatureVector: (not shown)" << std::endl;
+    ss << segmentData.toStdString(indent+1);
+    return ss.str();
+}
+
+
+void PositionData::print(unsigned int indent)
+{
+    std::cout << toStdString(indent);
+}
+
+
 // HogPositionFitterData
 // ----------------------------------------------------------------------------
 HogPositionFitterData::HogPositionFitterData() {};

File src/demo/fly_sorter/hog_position_fitter.hpp

 #include "fly_segmenter.hpp"
 #include <list>
 #include <vector>
+#include <string>
 #include <opencv2/core/core.hpp>
 
 //Debug 
         SegmentData segmentData;
 
         PositionData();
+        std::string toStdString(unsigned int indent=0);
+        void print(unsigned int indent=0);
 
         static const bool DEFAULT_IS_FLY;
         static const bool DEFAULT_IS_MULTIPLE_FLIES;

File src/demo/fly_sorter/identity_tracker.cpp

     BlobDataList::iterator it;
     for (it=blobFinderData.blobDataList.begin(); it!=blobFinderData.blobDataList.end(); it++)
     {
-        if ( (!(it -> isOnBorder())) && ((it -> id) == BlobData::ID_NOT_ASSIGNED))
+        if ((!(it -> isOnBorder())) && ((it -> id) == BlobData::ID_NOT_ASSIGNED))
         { 
             (it -> id) = idCounter_;
             idCounter_++;

File src/utility/blob_data.cpp

         std::string indentStr0 = getIndentString(indent);
         std::string indentStr1 = getIndentString(indent+1);
         ss << indentStr0 << "blobData:" << std::endl;
+        ss << indentStr1 << "id: " << id << std::endl;
         ss << indentStr1 << "area: " << area << std::endl;
         ss << indentStr1 << "onBorderX: " << onBorderX << std::endl;
         ss << indentStr1 << "onBorderY: " << onBorderY << std::endl;