• R/O
  • HTTP
  • SSH
  • HTTPS

NDNGestureVision: Commit

A utility class which tracks the movement of hands. The camera image is the input.
The output can be used for hand gesture analysis.


Commit MetaInfo

Revisión289f3ddc7575d6161181d52e0dbb1c503ad26408 (tree)
Tiempo2013-07-31 22:28:48
Autortkawata <takuji.kawata@gmai...>
Commitertkawata

Log Message

[NDNGestureVision] Added process view display / hide switch.

Cambiar Resumen

Diferencia incremental

--- a/ndngesturevision/ndngesturevision.cpp
+++ b/ndngesturevision/ndngesturevision.cpp
@@ -29,7 +29,7 @@
2929 #include <set>
3030
3131 NDNGestureVision::NDNGestureVision(int imageWidth, int imageHeight, int scanningStep, float minFlowThreshold, int numOfFlows)
32- : m_imageWidth(imageWidth), m_imageHeight(imageHeight), m_scanningStep(scanningStep), m_numOfFlows(numOfFlows)
32+ : m_imageWidth(imageWidth), m_imageHeight(imageHeight), m_scanningStep(scanningStep), m_numOfFlows(numOfFlows), m_drawProcessView(true)
3333 {
3434 assert(imageWidth > 0 && imageHeight > 0 && scanningStep > 0);
3535
@@ -584,7 +584,6 @@ void NDNGestureVision::calculateFlow(const cv::Mat &newImage, cv::Mat *pGestureV
584584 if (isGlobalMove)
585585 {
586586 //global move. Update background
587- isGlobalMove = true;
588587 if (m_focusedFlowRegion.age > 0)
589588 {
590589 float dx = m_focusedFlowRegion.direction.x * m_focusedFlowRegion.distance;
@@ -817,77 +816,80 @@ void NDNGestureVision::calculateFlow(const cv::Mat &newImage, cv::Mat *pGestureV
817816 */
818817 if (pGestureVisionDrawMat)
819818 {
820- int xs = pGestureVisionDrawMat->size().width / 4;
821- int ys = pGestureVisionDrawMat->size().height / 4;
822-
823- int xb = 0;
824- int scale = m_backgroundImage.size().width / xs;
825- int yy = 0;
826- int xx = 0;
827- for(int y = 0; y < ys; y++)
828- {
829- xx = 0;
830- for(int x = 0; x < xs; x++)
831- {
832- pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) = m_backgroundImage.at<cv::Vec3b>(yy,xx);
833- xx += scale;
834- }
835- yy += scale;
836- }
837-
838- xb += xs;
839- yy = 0;
840- int rt = 255 / m_backgroundMaxAge;
841- for(int y = 0; y < ys; y++)
819+ if (m_drawProcessView)
842820 {
843- xx = 0;
844- for(int x = 0; x < xs; x++)
845- {
846- int f = m_backgroundImageAge.at<uchar>(yy, xx) * rt;
847- pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) = cv::Vec3b(f,f,f);
848- xx += scale;
849- }
850- yy += scale;
851- }
821+ int xs = pGestureVisionDrawMat->size().width / 4;
822+ int ys = pGestureVisionDrawMat->size().height / 4;
852823
853- if (m_focusedFlowRegion.age > 0)
854- {
855- xb += xs;
856- float xscale = (float)(m_focusedFlowRegion.trackRegionX1 - m_focusedFlowRegion.trackRegionX0 + 1) / (float)xs;
857- float yscale = (float)(m_focusedFlowRegion.trackRegionY1 - m_focusedFlowRegion.trackRegionY0 + 1) / (float)ys;
858- float fscale = xscale < yscale ? yscale : xscale;
859-
860- float fyy = 0;
824+ int xb = 0;
825+ int scale = m_backgroundImage.size().width / xs;
826+ int yy = 0;
827+ int xx = 0;
861828 for(int y = 0; y < ys; y++)
862829 {
863- float fxx = 0;
830+ xx = 0;
864831 for(int x = 0; x < xs; x++)
865832 {
866- pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) = m_trackingImage.at<cv::Vec3b>((int)fyy, (int)fxx);
867- fxx += fscale;
833+ pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) = m_backgroundImage.at<cv::Vec3b>(yy,xx);
834+ xx += scale;
868835 }
869- fyy += fscale;
836+ yy += scale;
870837 }
871- }
872838
873- if (foregroundImg.size().width > 0)
874- {
875839 xb += xs;
876- scale = foregroundImg.size().width / xs;
877840 yy = 0;
841+ int rt = 255 / m_backgroundMaxAge;
878842 for(int y = 0; y < ys; y++)
879843 {
880844 xx = 0;
881845 for(int x = 0; x < xs; x++)
882846 {
883- int f = foregroundImg.at<uchar>(yy, xx);
884- {
885- pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) = cv::Vec3b(f,f,f);
886- }
847+ int f = m_backgroundImageAge.at<uchar>(yy, xx) * rt;
848+ pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) = cv::Vec3b(f,f,f);
887849 xx += scale;
888850 }
889851 yy += scale;
890852 }
853+
854+ if (m_focusedFlowRegion.age > 0)
855+ {
856+ xb += xs;
857+ float xscale = (float)(m_focusedFlowRegion.trackRegionX1 - m_focusedFlowRegion.trackRegionX0 + 1) / (float)xs;
858+ float yscale = (float)(m_focusedFlowRegion.trackRegionY1 - m_focusedFlowRegion.trackRegionY0 + 1) / (float)ys;
859+ float fscale = xscale < yscale ? yscale : xscale;
860+
861+ float fyy = 0;
862+ for(int y = 0; y < ys; y++)
863+ {
864+ float fxx = 0;
865+ for(int x = 0; x < xs; x++)
866+ {
867+ pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) = m_trackingImage.at<cv::Vec3b>((int)fyy, (int)fxx);
868+ fxx += fscale;
869+ }
870+ fyy += fscale;
871+ }
872+ }
873+
874+ if (foregroundImg.size().width > 0)
875+ {
876+ xb += xs;
877+ scale = foregroundImg.size().width / xs;
878+ yy = 0;
879+ for(int y = 0; y < ys; y++)
880+ {
881+ xx = 0;
882+ for(int x = 0; x < xs; x++)
883+ {
884+ int f = foregroundImg.at<uchar>(yy, xx);
885+ {
886+ pGestureVisionDrawMat->at<cv::Vec3b>(y,x + xb) = cv::Vec3b(f,f,f);
887+ }
888+ xx += scale;
889+ }
890+ yy += scale;
891+ }
892+ }
891893 }
892894
893895 if (m_focusedFlowRegion.age > 0)
--- a/ndngesturevision/ndngesturevision.h
+++ b/ndngesturevision/ndngesturevision.h
@@ -27,42 +27,42 @@ class NDNGestureVision
2727
2828 public:
2929
30- class FlowRegion
31- {
32- friend class NDNGestureVision;
30+ class FlowRegion
31+ {
32+ friend class NDNGestureVision;
3333
34- public:
34+ public:
3535 FlowRegion() : extent(0), distance(0), prevDistance(0), xmin(0), xmax(0), ymin(0), ymax(0), age(0)
36- {
37- }
38-
39- FlowRegion(const FlowRegion &flowRegion)
40- {
41- extent = flowRegion.extent;
42- direction = flowRegion.direction;
43- distance = flowRegion.distance;
44- xmin = flowRegion.xmin;
45- xmax = flowRegion.xmax;
46- ymin = flowRegion.ymin;
47- ymax = flowRegion.ymax;
36+ {
37+ }
38+
39+ FlowRegion(const FlowRegion &flowRegion)
40+ {
41+ extent = flowRegion.extent;
42+ direction = flowRegion.direction;
43+ distance = flowRegion.distance;
44+ xmin = flowRegion.xmin;
45+ xmax = flowRegion.xmax;
46+ ymin = flowRegion.ymin;
47+ ymax = flowRegion.ymax;
4848 prevDistance = flowRegion.prevDistance;
4949 _center = flowRegion._center;
50- age = flowRegion.age;
51- }
50+ age = flowRegion.age;
51+ }
5252
53- int extent;
54- cv::Point2f direction;
55- float distance;
53+ int extent;
54+ cv::Point2f direction;
55+ float distance;
5656 float prevDistance;
5757 int xmin;
58- int xmax;
59- int ymin;
60- int ymax;
61- int age;
58+ int xmax;
59+ int ymin;
60+ int ymax;
61+ int age;
6262
6363 cv::Point getCenter() const { return _center; }
6464
65- private:
65+ private:
6666 void calculateCenter()
6767 {
6868 assert(xmax >= xmin && ymax >= ymin);
@@ -77,21 +77,21 @@ public:
7777 int trackRegionX1;
7878 int trackRegionY1;
7979
80- };
80+ };
8181
8282 private:
83- int m_imageWidth;
84- int m_imageHeight;
85- int m_scanningXMax;
86- int m_scanningYMax;
87- int m_scanningStep;
88- int m_mapSize;
83+ int m_imageWidth;
84+ int m_imageHeight;
85+ int m_scanningXMax;
86+ int m_scanningYMax;
87+ int m_scanningStep;
88+ int m_mapSize;
8989 cv::Mat m_map;
9090 float m_minFlowThresholdP2;
91- int m_numOfFlows;
92- cv::Mat m_prevGray;
91+ int m_numOfFlows;
92+ cv::Mat m_prevGray;
9393
94- int *m_tempSortedFlowNums;
94+ int *m_tempSortedFlowNums;
9595 int *m_tempSortedFlowExtents;
9696
9797 FlowRegion m_focusedFlowRegion;
@@ -119,22 +119,25 @@ private:
119119 int m_forgroundNoiseThreashold;
120120 int m_focusedRegionMaxAge;
121121 int m_focusedRegionInitAge;
122+ bool m_drawProcessView;
122123
123124 public:
124125 NDNGestureVision(int imageWidth, int imageHeight, int scanningStep = 4, float minFlowThreshold = 1, int numOfFlows = 3);
125- ~NDNGestureVision();
126+ ~NDNGestureVision();
126127
127128 float getTrackingImageGoodScore() const { return m_fousedRegionMatchingGoodScore; }
128129 float getTrackingImageAcceptScore() const { return m_fousedRegionMatchingAcceptScore; }
129130 int getFocusedRegionMaxAge() const { return m_focusedRegionMaxAge; }
130131 int getFocusedRegionInitAge() const { return m_focusedRegionInitAge; }
131132 int getImageDiffThreshold() const { return m_backgroundDiffThreshold; }
133+ bool getDrawProcessView() const { return m_drawProcessView; }
132134
133135 void setTrackingImageGoodScore(float in) { m_fousedRegionMatchingGoodScore = in; }
134136 void setTrackingImageAcceptScore(float in) { m_fousedRegionMatchingAcceptScore = in; }
135137 void setFocusedRegionMaxAge(int in) { m_focusedRegionMaxAge = in; }
136138 void setFocusedRegionInitAge(int in) { m_focusedRegionInitAge = in; }
137139 void setImageDiffThreshold(int in) { m_backgroundDiffThreshold = in; }
140+ void setDrawProcessView(bool in) { m_drawProcessView = in; }
138141
139142 const FlowRegion* getFlow(int index = 0) const;
140143 void calculateFlow(const cv::Mat &newImage, cv::Mat *pGestureVisionDrawMat = NULL);
Show on old repository browser