OSDN Git Service

[NDNGestureVision] Added process view display / hide switch. master
authortkawata <takuji.kawata@gmail.com>
Wed, 31 Jul 2013 13:28:48 +0000 (22:28 +0900)
committertkawata <takuji.kawata@gmail.com>
Wed, 31 Jul 2013 13:28:48 +0000 (22:28 +0900)
ndngesturevision/ndngesturevision.cpp
ndngesturevision/ndngesturevision.h

index 0565803..fea2661 100644 (file)
@@ -29,7 +29,7 @@
 #include <set>
 
 NDNGestureVision::NDNGestureVision(int imageWidth, int imageHeight, int scanningStep, float minFlowThreshold, int numOfFlows)
-    : m_imageWidth(imageWidth), m_imageHeight(imageHeight), m_scanningStep(scanningStep), m_numOfFlows(numOfFlows)
+    : m_imageWidth(imageWidth), m_imageHeight(imageHeight), m_scanningStep(scanningStep), m_numOfFlows(numOfFlows), m_drawProcessView(true)
 {
     assert(imageWidth > 0 && imageHeight > 0 && scanningStep > 0);
 
@@ -584,7 +584,6 @@ void NDNGestureVision::calculateFlow(const cv::Mat &newImage, cv::Mat *pGestureV
         if (isGlobalMove)
         {
             //global move. Update background
-            isGlobalMove = true;
             if (m_focusedFlowRegion.age > 0)
             {
                 float dx = m_focusedFlowRegion.direction.x * m_focusedFlowRegion.distance;
@@ -817,77 +816,80 @@ void NDNGestureVision::calculateFlow(const cv::Mat &newImage, cv::Mat *pGestureV
          */
         if (pGestureVisionDrawMat)
         {
-            int xs = pGestureVisionDrawMat->size().width / 4;
-            int ys = pGestureVisionDrawMat->size().height / 4;
-
-            int xb = 0;
-            int scale = m_backgroundImage.size().width / xs;
-            int yy = 0;
-            int xx = 0;
-            for(int y = 0; y < ys; y++)
-            {
-                xx = 0;
-                for(int x = 0; x < xs; x++)
-                {
-                    pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) =  m_backgroundImage.at<cv::Vec3b>(yy,xx);
-                    xx += scale;
-                }
-                yy += scale;
-            }
-
-            xb += xs;
-            yy = 0;
-            int rt = 255 / m_backgroundMaxAge;
-            for(int y = 0; y < ys; y++)
+            if (m_drawProcessView)
             {
-                xx = 0;
-                for(int x = 0; x < xs; x++)
-                {
-                    int f = m_backgroundImageAge.at<uchar>(yy, xx) * rt;
-                    pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) =  cv::Vec3b(f,f,f);
-                    xx += scale;
-                }
-                yy += scale;
-            }
+                int xs = pGestureVisionDrawMat->size().width / 4;
+                int ys = pGestureVisionDrawMat->size().height / 4;
 
-            if (m_focusedFlowRegion.age > 0)
-            {
-                xb += xs;
-                float xscale = (float)(m_focusedFlowRegion.trackRegionX1 - m_focusedFlowRegion.trackRegionX0 + 1) / (float)xs;
-                float yscale = (float)(m_focusedFlowRegion.trackRegionY1 - m_focusedFlowRegion.trackRegionY0 + 1) / (float)ys;
-                float fscale = xscale < yscale ? yscale : xscale;
-
-                float fyy = 0;
+                int xb = 0;
+                int scale = m_backgroundImage.size().width / xs;
+                int yy = 0;
+                int xx = 0;
                 for(int y = 0; y < ys; y++)
                 {
-                    float fxx = 0;
+                    xx = 0;
                     for(int x = 0; x < xs; x++)
                     {
-                        pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) =  m_trackingImage.at<cv::Vec3b>((int)fyy, (int)fxx);
-                        fxx += fscale;
+                        pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) =  m_backgroundImage.at<cv::Vec3b>(yy,xx);
+                        xx += scale;
                     }
-                    fyy += fscale;
+                    yy += scale;
                 }
-            }
 
-            if (foregroundImg.size().width > 0)
-            {
                 xb += xs;
-                scale = foregroundImg.size().width / xs;
                 yy = 0;
+                int rt = 255 / m_backgroundMaxAge;
                 for(int y = 0; y < ys; y++)
                 {
                     xx = 0;
                     for(int x = 0; x < xs; x++)
                     {
-                        int f = foregroundImg.at<uchar>(yy, xx);
-                        {
-                            pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) =  cv::Vec3b(f,f,f);
-                        }
+                        int f = m_backgroundImageAge.at<uchar>(yy, xx) * rt;
+                        pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) =  cv::Vec3b(f,f,f);
                         xx += scale;
                     }
                     yy += scale;
                 }
+
+                if (m_focusedFlowRegion.age > 0)
+                {
+                    xb += xs;
+                    float xscale = (float)(m_focusedFlowRegion.trackRegionX1 - m_focusedFlowRegion.trackRegionX0 + 1) / (float)xs;
+                    float yscale = (float)(m_focusedFlowRegion.trackRegionY1 - m_focusedFlowRegion.trackRegionY0 + 1) / (float)ys;
+                    float fscale = xscale < yscale ? yscale : xscale;
+
+                    float fyy = 0;
+                    for(int y = 0; y < ys; y++)
+                    {
+                        float fxx = 0;
+                        for(int x = 0; x < xs; x++)
+                        {
+                            pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) =  m_trackingImage.at<cv::Vec3b>((int)fyy, (int)fxx);
+                            fxx += fscale;
+                        }
+                        fyy += fscale;
+                    }
+                }
+
+                if (foregroundImg.size().width > 0)
+                {
+                    xb += xs;
+                    scale = foregroundImg.size().width / xs;
+                    yy = 0;
+                    for(int y = 0; y < ys; y++)
+                    {
+                        xx = 0;
+                        for(int x = 0; x < xs; x++)
+                        {
+                            int f = foregroundImg.at<uchar>(yy, xx);
+                            {
+                                pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) =  cv::Vec3b(f,f,f);
+                            }
+                            xx += scale;
+                        }
+                        yy += scale;
+                    }
+                }
             }
 
             if (m_focusedFlowRegion.age > 0)
index 233bdbb..27535fa 100644 (file)
@@ -27,42 +27,42 @@ class NDNGestureVision
 
 public:
 
-       class FlowRegion
-       {
-               friend class NDNGestureVision;
+    class FlowRegion
+    {
+        friend class NDNGestureVision;
 
-       public:
+    public:
         FlowRegion() : extent(0), distance(0), prevDistance(0), xmin(0), xmax(0), ymin(0), ymax(0), age(0)
-               {
-               }
-
-               FlowRegion(const FlowRegion &flowRegion)
-               {
-                       extent = flowRegion.extent;
-                       direction = flowRegion.direction;
-                       distance = flowRegion.distance;
-                       xmin = flowRegion.xmin;
-                       xmax = flowRegion.xmax;
-                       ymin = flowRegion.ymin;
-                       ymax = flowRegion.ymax;
+        {
+        }
+
+        FlowRegion(const FlowRegion &flowRegion)
+        {
+            extent = flowRegion.extent;
+            direction = flowRegion.direction;
+            distance = flowRegion.distance;
+            xmin = flowRegion.xmin;
+            xmax = flowRegion.xmax;
+            ymin = flowRegion.ymin;
+            ymax = flowRegion.ymax;
             prevDistance = flowRegion.prevDistance;
             _center = flowRegion._center;
-                       age = flowRegion.age;
-               }
+            age = flowRegion.age;
+        }
 
-               int                     extent;
-               cv::Point2f direction;
-               float           distance;
+        int                    extent;
+        cv::Point2f direction;
+        float          distance;
         float          prevDistance;
         int                    xmin;
-               int                     xmax;
-               int                     ymin;
-               int                     ymax;
-               int                     age;
+        int                    xmax;
+        int                    ymin;
+        int                    ymax;
+        int                    age;
 
         cv::Point      getCenter() const { return _center; }
 
-       private:
+    private:
         void           calculateCenter()
         {
             assert(xmax >= xmin && ymax >= ymin);
@@ -77,21 +77,21 @@ public:
         int         trackRegionX1;
         int         trackRegionY1;
 
-       };
+    };
 
 private:
-       int                             m_imageWidth;
-       int                             m_imageHeight;
-       int                             m_scanningXMax;
-       int                             m_scanningYMax;
-       int                             m_scanningStep;
-       int                             m_mapSize;
+    int                                m_imageWidth;
+    int                                m_imageHeight;
+    int                                m_scanningXMax;
+    int                                m_scanningYMax;
+    int                                m_scanningStep;
+    int                                m_mapSize;
     cv::Mat         m_map;
     float                      m_minFlowThresholdP2;
-       int                             m_numOfFlows;
-       cv::Mat                 m_prevGray;
+    int                                m_numOfFlows;
+    cv::Mat                    m_prevGray;
 
-       int                             *m_tempSortedFlowNums;
+    int                                *m_tempSortedFlowNums;
     int                                *m_tempSortedFlowExtents;
 
     FlowRegion      m_focusedFlowRegion;
@@ -119,22 +119,25 @@ private:
     int             m_forgroundNoiseThreashold;
     int             m_focusedRegionMaxAge;
     int             m_focusedRegionInitAge;
+    bool            m_drawProcessView;
 
 public:
     NDNGestureVision(int imageWidth, int imageHeight, int scanningStep = 4, float minFlowThreshold = 1, int numOfFlows = 3);
-       ~NDNGestureVision();
+    ~NDNGestureVision();
 
     float           getTrackingImageGoodScore() const { return m_fousedRegionMatchingGoodScore; }
     float           getTrackingImageAcceptScore() const { return m_fousedRegionMatchingAcceptScore; }
     int             getFocusedRegionMaxAge() const { return m_focusedRegionMaxAge; }
     int             getFocusedRegionInitAge() const { return m_focusedRegionInitAge; }
     int             getImageDiffThreshold() const { return m_backgroundDiffThreshold; }
+    bool            getDrawProcessView() const { return m_drawProcessView; }
 
     void            setTrackingImageGoodScore(float in) { m_fousedRegionMatchingGoodScore = in; }
     void            setTrackingImageAcceptScore(float in) { m_fousedRegionMatchingAcceptScore = in; }
     void            setFocusedRegionMaxAge(int in) { m_focusedRegionMaxAge = in; }
     void            setFocusedRegionInitAge(int in) { m_focusedRegionInitAge = in; }
     void            setImageDiffThreshold(int in) { m_backgroundDiffThreshold = in; }
+    void            setDrawProcessView(bool in) { m_drawProcessView = in; }
 
     const FlowRegion* getFlow(int index = 0) const;
     void calculateFlow(const cv::Mat &newImage, cv::Mat *pGestureVisionDrawMat = NULL);