Commits

iorodeo committed 4fbe526

Worked on hog_position_fitter.

Comments (0)

Files changed (9)

src/demo/fly_sorter/CMakeLists.txt

     fly_sorter_window.hpp
     image_grabber.hpp
     parameters.hpp
+    fast_binary_predictor.hpp
     fly_segmenter.hpp
-    fast_binary_predictor.hpp
+    hog_position_fitter.hpp
     identity_tracker.hpp
     )
 
     fly_sorter_window.cpp
     image_grabber.cpp
     parameters.cpp
+    fast_binary_predictor.cpp
     fly_segmenter.cpp
-    fast_binary_predictor.cpp
+    hog_position_fitter.cpp
     identity_tracker.cpp
     )
 

src/demo/fly_sorter/fly_segmenter.cpp

     fastBinaryPredictor_.setClassifierParam(param_.classifier);
 }
 
-FlySegmenterData FlySegmenter::segment(BlobDataList blobDataList)
+FlySegmenterData FlySegmenter::segment(BlobFinderData blobFinderData)
 {
     //std::cout << __PRETTY_FUNCTION__ << std::endl;
 
     FlySegmenterData flySegmenterData;
-
+    BlobDataList blobDataList = blobFinderData.blobDataList;
     BlobDataList::iterator it;
 
     for (it=blobDataList.begin(); it!=blobDataList.end(); it++)

src/demo/fly_sorter/fly_segmenter.hpp

 };
 
 
-
 class FlySegmenter
 {
     public:
         FlySegmenter();
         FlySegmenter(FlySegmenterParam param);
         void setParam(FlySegmenterParam param);
-        FlySegmenterData segment(BlobDataList blobDataList);
+        FlySegmenterData segment(BlobFinderData blobFinderData);
 
     private:
 
         FlySegmenterParam param_;
         FastBinaryPredictor fastBinaryPredictor_;
-
 };
 
 

src/demo/fly_sorter/fly_sorter_window.cpp

 #include <iostream>
 #include <list>
 #include <random>
+#include <cmath>
 
 // Constants
 // ----------------------------------------------------------------------------
     blobFinderData_ = blobFinder.findBlobs(imageData.mat);
 
     FlySegmenter flySegmenter = FlySegmenter(param_.flySegmenter);
-    flySegmenterData_ = flySegmenter.segment(blobFinderData_.blobDataList);
+    flySegmenterData_ = flySegmenter.segment(blobFinderData_);
+
+    HogPositionFitter hogPositionFitter = HogPositionFitter(param_.hogPositionFitter);
+    hogPositionData_ = hogPositionFitter.fit(flySegmenterData_);
+    
 
     if ((httpOutputCheckBoxPtr_ -> checkState()) == Qt::Checked)
     {
     // --------------------------------------------------------------------------
     QString appDirPath = QCoreApplication::applicationDirPath();
     std::cout << "applicationDirPath = " << appDirPath.toStdString() << std::endl;
-
     distribution_ = std::uniform_int_distribution<unsigned int>(0,1);
 
+    int n = 15;
+    int m = 2*n+1;
+    cv::Mat se = cv::getStructuringElement(cv::MORPH_ELLIPSE,cv::Size(m,m));
+    for (int i=0; i<m; i++)
+    {
+        for (int j=0; j<m; j++)
+        {
+            std::cout << int(se.at<uchar>(i,j)) << " ";
+        }
+        std::cout << std::endl;
+    }
 
 }
 

src/demo/fly_sorter/fly_sorter_window.hpp

 #include "image_grabber.hpp"
 #include "blob_finder.hpp"
 #include "fly_segmenter.hpp"
+#include "hog_position_fitter.hpp"
 #include <memory>
 #include <QCloseEvent>
 #include <QMainWindow>
         ImageData imageData_;
         BlobFinderData blobFinderData_;
         FlySegmenterData flySegmenterData_;
+        HogPositionData hogPositionData_;
         unsigned int httpRequestErrorCount_;
         QString parameterFileName_;
 

src/demo/fly_sorter/hog_position_fitter.cpp

+#include "hog_position_fitter.hpp"
+#include <iostream>
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+
+HogPositionFitter::HogPositionFitter() {};
+
+HogPositionFitter::HogPositionFitter(HogPositionFitterParam param)
+{
+    setParam(param);
+};
+
+void HogPositionFitter::setParam(HogPositionFitterParam param)
+{
+    param_ = param;
+}
+
+
+HogPositionData HogPositionFitter::fit(FlySegmenterData flySegmenterData)
+{
+    std::cout << __PRETTY_FUNCTION__ << std::endl;
+
+    SegmentDataList segmentDataList = flySegmenterData.segmentDataList;
+    SegmentDataList::iterator it;
+
+    for (it=segmentDataList.begin(); it!=segmentDataList.end(); it++)
+    {
+        SegmentData segmentData = *it;
+        std::cout << "  processing segment data" << std::endl;
+        
+        // Perform morphological close and open operations
+        unsigned int elemDiam = 2*param_.closeRadius + 1;
+        cv::Size elemSize = cv::Size(elemDiam,elemDiam);
+        cv::Mat closeStructElem = cv::getStructuringElement(cv::MORPH_ELLIPSE, elemSize);
+        cv::Mat fitMat = segmentData.predictorData.fit;
+        cv::Mat closeMat = cv::Mat(fitMat.size(),fitMat.type());
+        cv::morphologyEx(fitMat,closeMat,cv::MORPH_CLOSE,closeStructElem);
+
+        // Apply bwarea open
+    }
+
+}
+
+
+

src/demo/fly_sorter/hog_position_fitter.hpp

+#ifndef HOG_POSITION_FITTER
+#define HOG_POSITION_FITTER
+#include "parameters.hpp"
+#include "fly_segmenter.hpp"
+
+class HogPositionData
+{
+};
+
+class HogPositionFitter
+{
+    public:
+        HogPositionFitter();
+        HogPositionFitter(HogPositionFitterParam param);
+        void setParam(HogPositionFitterParam param);
+        HogPositionData fit(FlySegmenterData flySegmenterData);
+
+    private:
+        HogPositionFitterParam param_;
+
+};
+
+#endif

src/demo/fly_sorter/parameters.cpp

     classifier = DEFAULT_CLASSIFIER_PARAM;
 };
 
+// HogPositionFitterParam
+// ----------------------------------------------------------------------------
+
+
+
+const unsigned int HogPositionFitterParam::DEFAULT_CLOSE_RADIUS = 15;
+const unsigned int HogPositionFitterParam::DEFAULT_OPEN_AREA = 3400;
+
+HogPositionFitterParam::HogPositionFitterParam()
+{
+    closeRadius = DEFAULT_CLOSE_RADIUS;
+    openArea = DEFAULT_OPEN_AREA;
+}
+
 // ImageGrabberParam
 // ----------------------------------------------------------------------------
 
 
 FlySorterParam::FlySorterParam()
 {
-    server = ServerParam();
-    imageGrabber = ImageGrabberParam();
-    blobFinder = BlobFinderParam();
+    
+    //server = ServerParam();
+    //imageGrabber = ImageGrabberParam();
+    //blobFinder = BlobFinderParam();
+    //flySegmenter = FlySegmenterParam();
+    //hogPositionFitter = HogPositionFitterParam();
+    
     // Devel
     // -------------------------------
     genderMode = GenderModeMaleOnly;

src/demo/fly_sorter/parameters.hpp

 };
 
 
-class FlySegmenterParam : public ClassifierParam
+class FlySegmenterParam 
 {
     public:
 
 };
 
 
+class HogPositionFitterParam 
+{
+    public:
+
+        unsigned int closeRadius;
+        static const unsigned int DEFAULT_CLOSE_RADIUS;
+
+        unsigned int openArea;
+        static const unsigned int DEFAULT_OPEN_AREA;
+
+        HogPositionFitterParam();
+};
+
+
 class ImageGrabberParam
 {
     public:
         ImageGrabberParam imageGrabber;
         BlobFinderParam blobFinder;
         FlySegmenterParam flySegmenter;
+        HogPositionFitterParam hogPositionFitter;
 
         // Devel
         // -------------------