Commits

iorodeo committed 6d7f278

Worked on HogPositionFitter and PixelFeatureVector.

  • Participants
  • Parent commits 489593e

Comments (0)

Files changed (6)

src/demo/fly_sorter/fast_binary_predictor.cpp

 
     // Get labels - is there any reason not to use binary labels?
     data.label = cv::Mat(data.fit.size(),data.fit.type(),cv::Scalar(0.0));
-    cv::threshold(data.fit,data.label,0.0,255,CV_THRESH_BINARY);
+    cv::threshold(data.fit,data.label,0.0,255.0,CV_THRESH_BINARY);
     data.label.convertTo(data.label,CV_8UC1);
     return data;
 }

src/demo/fly_sorter/fly_segmenter.cpp

 FlySegmenter::FlySegmenter(FlySegmenterParam param)
 {
     setParam(param);
-    showDebugWindow_ = false;
+    showDebugWindow_ = false; 
     if (showDebugWindow_) 
     {
         cv::namedWindow(
         {
             boundingImageBGR = blobData.boundingImage;
         }
+
         cv::Mat boundingImageLUV = cv::Mat(
                 boundingImageBGR.size(), 
                 boundingImageBGR.type(),
                 cv::Scalar(0,0,0)
                 );
+
         cv::cvtColor(boundingImageBGR,boundingImageLUV,CV_BGR2Luv);
 
         // Segment using fast binary predict.
         // --------------------------------------------------------
         
         flySegmenterData.segmentDataList.push_back(segmentData);
+
+        // DEVELOP TEMPORARY    
+        // --------------------------------------------------------
         if (showDebugWindow_)
         {
             if (cnt==0)
             {
-                cv::imshow("FlySegmenter", segmentData.predictorData.label);
-                //cv::imshow("FlySegmenter", boundingImageLUV);
+                //cv::imshow("FlySegmenter", segmentData.predictorData.label);
+                cv::imshow("FlySegmenter", boundingImageLUV);
             }
         }
+        // ---------------------------------------------------------
         
     }
     return flySegmenterData;

src/demo/fly_sorter/hog_position_fitter.cpp

 #include "hog_position_fitter.hpp"
 #include "basic_image_proc.hpp"
+#include "fast_binary_predictor.hpp"
 #define _USE_MATH_DEFINES
 #include <cmath>
 #include <iostream>
 {
     isFly = DEFAULT_IS_FLY;
     isMultipleFlies = DEFAULT_IS_MULTIPLE_FLIES;
+    success = false;
     bodyArea = 0; 
     meanX = 0.0;
     meanY = 0.0;
 HogPositionFitter::HogPositionFitter(HogPositionFitterParam param)
 {
     setParam(param);
-    showDebugWindow_ = true;
+    showDebugWindow_ = false;
     if (showDebugWindow_)
     {
         //cv::namedWindow(
                 "hogPosMaxComp",
                 CV_WINDOW_AUTOSIZE | CV_WINDOW_KEEPRATIO | CV_GUI_EXPANDED
                 );
+        cv::namedWindow(
+                "boundingImageLUV",
+                CV_WINDOW_AUTOSIZE | CV_WINDOW_KEEPRATIO | CV_GUI_EXPANDED
+                );
+        cv::namedWindow(
+                "rotBoundingImageLUV",
+                CV_WINDOW_AUTOSIZE | CV_WINDOW_KEEPRATIO | CV_GUI_EXPANDED
+                );
     }
 };
 
             // right now, but you fix this to make is more is line with
             // matlab's function. 
             posData.isFly = false;
+            posData.success = false;
             fitterData.positionDataList.push_back(posData);
             continue;
         }
                 posData.meanX = meanPos.val[0];
                 posData.meanY = meanPos.val[1];
                 fitterData.positionDataList.push_back(posData);
+                posData.success = false;
                 continue;
             }
             else 
             posData.ellipseAngle = std::atan2(eigenVec.at<double>(0,1),eigenVec.at<double>(0,0));
             posData.ellipseAngle = std::fmod(posData.ellipseAngle + 0.5*M_PI,M_PI) - 0.5*M_PI;
 
-            std::cout << "major axis: " << posData.ellipseMajorAxis << std::endl;
-            std::cout << "minor axis: " << posData.ellipseMinorAxis << std::endl;
-            std::cout << "angle:      " << posData.ellipseAngle << std::endl;
+             
+            // Rotate fly image using affine transform
+            double rotAngDeg = (posData.ellipseAngle + 0.5*M_PI)*180.0/M_PI;
+            cv::Point2f rotCenter = cv::Point2f(posData.meanX, posData.meanY);
+            cv::Mat rotMat = cv::getRotationMatrix2D(rotCenter, rotAngDeg, 1.0);
 
+            double shiftX = -rotCenter.x + posData.ellipseMinorAxis + param_.padBorder;
+            double shiftY = -rotCenter.y + posData.ellipseMajorAxis + param_.padBorder;
+            rotMat.at<double>(0,2) = rotMat.at<double>(0,2) + shiftX;
+            rotMat.at<double>(1,2) = rotMat.at<double>(1,2) + shiftY;
+
+            cv::Size imageSize =cv::Size(
+                    2*(posData.ellipseMinorAxis + param_.padBorder),
+                    2*(posData.ellipseMajorAxis + param_.padBorder)
+                    );
+           
+            int imageType = segmentData.boundingImageLUV.type();
+            cv::Mat rotBoundingImageLUV = cv::Mat(imageSize,imageType);
+            cv::warpAffine(
+                    segmentData.boundingImageLUV,
+                    rotBoundingImageLUV,
+                    rotMat,
+                    imageSize,
+                    cv::INTER_LINEAR,
+                    cv::BORDER_CONSTANT,
+                    param_.fillValuesLUV*255.0
+                    );
+
+            // Get pixel feature vector
+            cv::Mat pixelFeatureVector = getPixelFeatureVector(rotBoundingImageLUV);
+
+            // Classify orientation
+            //FastBinaryPredictor predictory = FastBinaryPredictor();
+            //FastBinaryPredictorData predictorData = F
+
+
+            // Flip pixel feature vector and rotated LUV bounding image if required.
+
+
+
+
+            posData.success = true;
+
+            // Temporary
+            // ---------------------------------------------------------------------
             if (showDebugWindow_)
             {
                 if (cnt==0)
                     //cv::imshow("hogPosClose", closeMat);
                     //cv::imshow("hogPosIsBody", isBodyMat);
                     cv::imshow("hogPosMaxComp", maxCompMat);
+                    cv::imshow("boundingImageLUV", segmentData.boundingImageLUV);
+                    cv::imshow("rotBoundingImageLUV", rotBoundingImageLUV);
                 }
             }
+            // ----------------------------------------------------------------------
         }
 
 
 }
 
 
+cv::Mat HogPositionFitter::getPixelFeatureVector(cv::Mat image)
+{
+    cv::Mat pixelFeatureVector;
+    return pixelFeatureVector;
+}
 
 
 
+
+

src/demo/fly_sorter/hog_position_fitter.hpp

 {
     public:
 
+        bool success;
         bool isFly;
         bool isMultipleFlies;
         unsigned int bodyArea;
     private:
         bool showDebugWindow_;
         HogPositionFitterParam param_;
+        cv::Mat getPixelFeatureVector(cv::Mat image);
 
 };
 

src/demo/fly_sorter/parameters.cpp

 
 // FlySegmenterParam
 // ----------------------------------------------------------------------------
+
+// TEMPORARY - kludgey, but I just need some data for developing 
+// the fly segmenter. We will read this from a file later.
+// ----------------------------------------------------------------------------
 ClassifierParam FlySegmenterParam::createDefaultClassifierParam()
 {
-    // -------------------------------------------------------------
-    // TEMPORARY - kludgey, but I just need some data for developing 
-    // the fly segmenter. We will read this from a file later.
-    // -------------------------------------------------------------
     ClassifierParam classifierParam;
     classifierParam.offset = 1.0784;
     std::vector<StumpData> stumpVector;
 };
 const ClassifierParam FlySegmenterParam::DEFAULT_CLASSIFIER_PARAM = 
 createDefaultClassifierParam();
+// ----------------------------------------------------------------------------
 
 
 FlySegmenterParam::FlySegmenterParam()
 
 const unsigned int HogPositionFitterParam::DEFAULT_CLOSE_RADIUS = 15;
 const unsigned int HogPositionFitterParam::DEFAULT_OPEN_AREA = 3400;
-const unsigned int HogPositionFitterParam::DEFAULT_MAX_BODY_AREA=16600;
-std::vector<double> HogPositionFitterParam::createDefaultFillValuesLUV()
+const unsigned int HogPositionFitterParam::DEFAULT_MAX_BODY_AREA = 16600;
+const cv::Scalar HogPositionFitterParam::DEFAULT_FILL_VALUES_LUV =
+cv::Scalar(0.3703704,0.3259259,0.4962940); 
+const double HogPositionFitterParam::DEFAULT_PAD_BORDER = 1.1;
+
+// TEMPORARY - kludgey, but I just need some data for developing 
+// the fly segmenter. We will read this from a file later.
+// ----------------------------------------------------------------------------
+ClassifierParam HogPositionFitterParam::createDefaultOrientClassifierParam()
 {
-    std::vector<double> fillValues;
-    fillValues.push_back(0.3703704);
-    fillValues.push_back(0.3259259);
-    fillValues.push_back(0.4962940);
-    return fillValues;
-}
-const std::vector<double> HogPositionFitterParam::DEFAULT_FILL_VALUES_LUV =
-createDefaultFillValuesLUV();
-
+    ClassifierParam classifierParam;
+    classifierParam.offset = -16.7966;
+    std::vector<StumpData> stumpVector;
+    stumpVector.push_back(StumpData(112, 0.002833, 1.983723));
+    stumpVector.push_back(StumpData(232, 0.002833, -1.984202));
+    stumpVector.push_back(StumpData(115, 0.008012, -1.959708));
+    stumpVector.push_back(StumpData(235, 0.008211, 1.950887));
+    stumpVector.push_back(StumpData(37, 0.306614, -1.851272));
+    stumpVector.push_back(StumpData(25, 0.306401, 1.875527));
+    stumpVector.push_back(StumpData(236, 0.016120, 1.680340));
+    stumpVector.push_back(StumpData(202, 0.000407, -1.743562));
+    stumpVector.push_back(StumpData(146, 0.027317, -1.706087));
+    stumpVector.push_back(StumpData(142, 0.000407, 1.763328));
+    stumpVector.push_back(StumpData(116, 0.015109, -1.735205));
+    stumpVector.push_back(StumpData(206, 0.027317, 1.629330));
+    stumpVector.push_back(StumpData(115, 0.011560, -1.437190));
+    stumpVector.push_back(StumpData(236, 0.015109, 1.630453));
+    stumpVector.push_back(StumpData(201, 0.011108, -1.603780));
+    stumpVector.push_back(StumpData(141, 0.011108, 1.616170));
+    stumpVector.push_back(StumpData(235, 0.011560, 1.495133));
+    stumpVector.push_back(StumpData(116, 0.016120, -1.601133));
+    stumpVector.push_back(StumpData(899, 0.275501, 1.520732));
+    stumpVector.push_back(StumpData(911, 0.278920, -1.632418));
+    stumpVector.push_back(StumpData(232, 0.003976, -1.556266));
+    stumpVector.push_back(StumpData(202, 0.001525, -1.577791));
+    stumpVector.push_back(StumpData(112, 0.003976, 1.648567));
+    stumpVector.push_back(StumpData(142, 0.001525, 1.586624));
+    stumpVector.push_back(StumpData(204, 0.019942, 1.588415));
+    stumpVector.push_back(StumpData(416, 0.031681, -1.499144));
+    stumpVector.push_back(StumpData(236, 0.012951, 1.621361));
+    stumpVector.push_back(StumpData(111, 0.006901, 1.644504));
+    stumpVector.push_back(StumpData(34, 0.311323, -1.517389));
+    stumpVector.push_back(StumpData(235, 0.011560, 1.553500));
+    stumpVector.push_back(StumpData(202, 0.002242, -1.598525));
+    stumpVector.push_back(StumpData(141, 0.012292, 1.522593));
+    stumpVector.push_back(StumpData(116, 0.012951, -1.594934));
+    stumpVector.push_back(StumpData(232, 0.002833, -1.586161));
+    stumpVector.push_back(StumpData(536, 0.031681, 1.591355));
+    stumpVector.push_back(StumpData(144, 0.019891, -1.513393));
+    stumpVector.push_back(StumpData(201, 0.003731, -1.542618));
+    stumpVector.push_back(StumpData(28, 0.313313, 1.369082));
+    stumpVector.push_back(StumpData(116, 0.016711, -1.449301));
+    stumpVector.push_back(StumpData(142, 0.000071, 1.430221));
+    stumpVector.push_back(StumpData(231, 0.007153, -1.574709));
+    stumpVector.push_back(StumpData(144, 0.019942, -1.558897));
+    stumpVector.push_back(StumpData(536, 0.031681, 1.438624));
+    stumpVector.push_back(StumpData(115, 0.011560, -1.582286));
+    stumpVector.push_back(StumpData(64, 0.329356, -1.562409));
+    stumpVector.push_back(StumpData(384, 0.009421, 1.402641));
+    stumpVector.push_back(StumpData(116, 0.013351, -1.419670));
+    stumpVector.push_back(StumpData(28, 0.313648, 1.458448));
+    stumpVector.push_back(StumpData(124, 0.064568, -1.353391));
+    stumpVector.push_back(StumpData(232, 0.003976, -1.546833));
+    stumpVector.push_back(StumpData(202, 0.000071, -1.448950));
+    stumpVector.push_back(StumpData(112, 0.002833, 1.625674));
+    stumpVector.push_back(StumpData(236, 0.016711, 1.558370));
+    stumpVector.push_back(StumpData(899, 0.278920, 1.478915));
+    stumpVector.push_back(StumpData(224, 0.010015, 1.430835));
+    stumpVector.push_back(StumpData(111, 0.008508, 1.570713));
+    stumpVector.push_back(StumpData(187, 0.267372, -1.617410));
+    stumpVector.push_back(StumpData(807, 0.069382, 1.576354));
+    stumpVector.push_back(StumpData(416, 0.032240, -1.557547));
+    stumpVector.push_back(StumpData(142, 0.000156, 1.445432));
+    stumpVector.push_back(StumpData(25, 0.306548, 1.598108));
+    stumpVector.push_back(StumpData(236, 0.013351, 1.516873));
+    stumpVector.push_back(StumpData(34, 0.313382, -1.527913));
+    stumpVector.push_back(StumpData(115, 0.011560, -1.454917));
+    stumpVector.push_back(StumpData(142, 0.001052, 1.581576));
+    stumpVector.push_back(StumpData(144, 0.019942, -1.538615));
+    stumpVector.push_back(StumpData(37, 0.306727, -1.625760));
+    stumpVector.push_back(StumpData(116, 0.016711, -1.523061));
+    stumpVector.push_back(StumpData(235, 0.011560, 1.427218));
+    stumpVector.push_back(StumpData(202, 0.000914, -1.565892));
+    stumpVector.push_back(StumpData(204, 0.019891, 1.565615));
+    stumpVector.push_back(StumpData(141, 0.012014, 1.623432));
+    stumpVector.push_back(StumpData(236, 0.016711, 1.335551));
+    stumpVector.push_back(StumpData(201, 0.011121, -1.536721));
+    stumpVector.push_back(StumpData(127, 0.228118, 1.583106));
+    stumpVector.push_back(StumpData(911, 0.278920, -1.405823));
+    stumpVector.push_back(StumpData(232, 0.002833, -1.540978));
+    stumpVector.push_back(StumpData(116, 0.012951, -1.595306));
+    stumpVector.push_back(StumpData(536, 0.031681, 1.536796));
+    stumpVector.push_back(StumpData(787, 0.068775, -1.476896));
+    stumpVector.push_back(StumpData(187, 0.272392, -1.488366));
+    stumpVector.push_back(StumpData(112, 0.002833, 1.546401));
+    stumpVector.push_back(StumpData(142, 0.000914, 1.513372));
+    stumpVector.push_back(StumpData(269, 0.112592, 0.809542));
+    stumpVector.push_back(StumpData(269, 0.112592, 0.997646));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    stumpVector.push_back(StumpData(269, 0.112592, 1.000000));
+    classifierParam.stumpVector = stumpVector;
+    return classifierParam;
+};
+const ClassifierParam HogPositionFitterParam::DEFAULT_ORIENT_CLASSIFIER_PARAM = 
+createDefaultOrientClassifierParam();
 
 HogPositionFitterParam::HogPositionFitterParam()
 {
     openArea = DEFAULT_OPEN_AREA;
     maxBodyArea = DEFAULT_MAX_BODY_AREA;
     fillValuesLUV = DEFAULT_FILL_VALUES_LUV;
+    padBorder = DEFAULT_PAD_BORDER;
+    orientClassifier = DEFAULT_ORIENT_CLASSIFIER_PARAM;
 }
 
 // ImageGrabberParam

src/demo/fly_sorter/parameters.hpp

 #include <vector>
 #include "blob_finder_param.hpp"
 #include "rtn_status.hpp"
+#include <opencv2/core/core.hpp>
 
 using namespace bias;
 
         unsigned int maxBodyArea;
         static const unsigned int DEFAULT_MAX_BODY_AREA;
 
-        std::vector<double> fillValuesLUV;
-        static const std::vector<double> DEFAULT_FILL_VALUES_LUV;
-        static std::vector<double> createDefaultFillValuesLUV();
+        cv::Scalar fillValuesLUV;
+        static const cv::Scalar DEFAULT_FILL_VALUES_LUV;
+
+        double padBorder;
+        static const double DEFAULT_PAD_BORDER;
+
+        ClassifierParam orientClassifier;
+        static const ClassifierParam DEFAULT_ORIENT_CLASSIFIER_PARAM;
+        static ClassifierParam createDefaultOrientClassifierParam();
 
         HogPositionFitterParam();
 };