Skip to content

Commit

Permalink
Build fixes for updated libs and initial VidPostureDetect
Browse files Browse the repository at this point in the history
  • Loading branch information
yodergj committed Apr 24, 2011
1 parent 0913bca commit 30ee5f4
Show file tree
Hide file tree
Showing 14 changed files with 797 additions and 54 deletions.
6 changes: 3 additions & 3 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ TARGET_LINK_LIBRARIES(dataAnalyzer gmm image geometry ${QT_QTCORE_LIBRARY} ${QT_
TARGET_LINK_LIBRARIES(fleshTrainer gmm image geometry ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2)
TARGET_LINK_LIBRARIES(fleshExtractor gmm image geometry ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2)
TARGET_LINK_LIBRARIES(blueRemover image geometry ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2)
TARGET_LINK_LIBRARIES(handTrainer hand flesh gmm image geometry utils ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2 cv)
TARGET_LINK_LIBRARIES(handTrainer hand flesh gmm image geometry utils ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2 opencv_core opencv_imgproc opencv_objdetect)
TARGET_LINK_LIBRARIES(handTruther image geometry utils ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
TARGET_LINK_LIBRARIES(nonHandTruther flesh gmm image geometry utils ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2)
TARGET_LINK_LIBRARIES(handExtractor hand flesh gmm image geometry utils ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2 cv)
TARGET_LINK_LIBRARIES(handWrapHaar hand gmm image geometry utils ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2 cv)
TARGET_LINK_LIBRARIES(handExtractor hand flesh gmm image geometry utils ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2 opencv_core opencv_imgproc opencv_objdetect)
TARGET_LINK_LIBRARIES(handWrapHaar hand gmm image geometry utils ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2 opencv_core opencv_imgproc opencv_objdetect)
TARGET_LINK_LIBRARIES(adaTrainer gmm image geometry ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2)
TARGET_LINK_LIBRARIES(adaExtractor gmm image geometry ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2)
TARGET_LINK_LIBRARIES(adaHandTrainer hand flesh gmm image geometry utils ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} xmlutils xml2)
Expand Down
61 changes: 40 additions & 21 deletions apps/postureDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "HandCandidate.h"
#include "Hand.h"
#include "SubImage.h"
#include "DirectoryUtils.h"

using std::string;

Expand All @@ -26,7 +27,6 @@ int main(int argc, char* argv[])
Hand* hand;
vector<HandCandidate*> handCandidates;
HandCandidate* candidate;
unsigned char boxColor[] = {255, 255, 255};
unsigned char angledBoxColor[] = {255, 255, 0};
unsigned char longColor[] = {0, 255, 0};
unsigned char shortColor[] = {0, 0, 255};
Expand All @@ -52,40 +52,48 @@ int main(int argc, char* argv[])
FILE* listFile;
vector<string> filenames;
int numFiles;
string outputDir, fullOutputFilename, subDir;

if ( argc < 4 )
if ( argc < 5 )
{
printf("Usage: %s <flesh classifier file> <hand classifier file> <image file> [ <image file> ... ]\n", argv[0]);
printf(" %s <flesh classifier file> <hand classifier file> -l <list file>\n", argv[0]);
printf("Usage: %s <output dir> <flesh classifier file> <hand classifier file> <image file> [ <image file> ... ]\n", argv[0]);
printf(" %s <output dir> <flesh classifier file> <hand classifier file> -l <list file>\n", argv[0]);
return 1;
}

outputDir = argv[1];
if ( !MakeDirectory(outputDir) )
{
fprintf(stderr, "Error creating output directory %s\n", outputDir.c_str());
return 1;
}

// Either loads a real detector or gets a dummy detector if arg is "DUMMY"
fleshDetector = FleshDetector::Get(argv[1]);
fleshDetector = FleshDetector::Get(argv[2]);
if ( !fleshDetector )
{
fprintf(stderr, "Error loading flesh detector %s\n", argv[1]);
fprintf(stderr, "Error loading flesh detector %s\n", argv[2]);
return 1;
}

if ( !postureDetector.Load(argv[2]) )
if ( !postureDetector.Load(argv[3]) )
{
fprintf(stderr, "Error loading hand detector %s\n", argv[2]);
fprintf(stderr, "Error loading hand detector %s\n", argv[3]);
return 1;
}
features = postureDetector.GetFeatureString();

if ( !strcmp(argv[3], "-l") )
if ( !strcmp(argv[4], "-l") )
{
if ( argc < 5 )
if ( argc < 6 )
{
fprintf(stderr, "List option given, but no list file specified.\n");
return 1;
}
listFile = fopen(argv[4], "r");
listFile = fopen(argv[5], "r");
if ( !listFile )
{
fprintf(stderr, "Failed opening list file %s\n", argv[4]);
fprintf(stderr, "Failed opening list file %s\n", argv[5]);
return 1;
}
char filename[4096];
Expand All @@ -95,17 +103,18 @@ int main(int argc, char* argv[])
}
else
{
for (i = 3; i < argc; i++)
for (i = 4; i < argc; i++)
filenames.push_back(argv[i]);
}
numFiles = filenames.size();

time(&currentTime);
strftime(outputFilename, 64, "postureResults-%Y%m%d-%H:%M:%S", localtime(&currentTime));
outputFile = fopen(outputFilename, "w");
fullOutputFilename = outputDir + "/" + outputFilename;
outputFile = fopen(fullOutputFilename.c_str(), "w");
if ( !outputFile )
{
fprintf(stderr, "Error opening output file %s - %s\n", outputFilename, strerror(errno));
fprintf(stderr, "Error opening output file %s - %s\n", fullOutputFilename.c_str(), strerror(errno));
return 1;
}
fprintf(outputFile, "Flesh Detection: %s\tPosture Detection: %s\n", argv[1], argv[2]);
Expand All @@ -125,6 +134,13 @@ int main(int argc, char* argv[])
if ( dotPos != (int)string::npos )
basename = basename.substr(0, dotPos);

subDir = GetDirectoryPart(basename);
if ( !MakeDirectory(outputDir + "/" + subDir) )
{
fprintf(stderr, "Error creating output directory %s\n", (outputDir + "/" + subDir).c_str());
return 1;
}

width = image.GetWidth();
height = image.GetHeight();

Expand Down Expand Up @@ -214,7 +230,6 @@ int main(int argc, char* argv[])
hand->SetPostureString(postureDetector.GetClassName(classIndex));
hands.push_back(hand);
printf("Detected Class %d %s\n", classIndex, hand->GetPostureString().c_str());
// TODO Graphical output of class
}

delete candidate;
Expand Down Expand Up @@ -248,7 +263,11 @@ int main(int argc, char* argv[])
{
fprintf(outputFile, " %s", hand->GetPostureString().c_str());
hands[j]->GetBounds(left, right, top, bottom);
outlineImage.DrawBox(boxColor, 3, left, top, right, bottom);
outlineImage.DrawBox(hands[j]->GetPostureColor(0),
hands[j]->GetPostureColor(1),
hands[j]->GetPostureColor(2),
hands[j]->GetPostureColor(3),
3, left, top, right, bottom);
delete hands[j];
}
if ( numHands == 0 )
Expand All @@ -257,12 +276,12 @@ int main(int argc, char* argv[])
hands.clear();
}

fleshImage->Save(basename + "_flesh.png");
confidenceImage->Save(basename + "_confidence.png");
outlineImage.Save(basename + "_frame.png");
fleshImage->Save(outputDir + "/" + basename + "_flesh.png");
confidenceImage->Save(outputDir + "/" + basename + "_confidence.png");
outlineImage.Save(outputDir + "/" + basename + "_frame.png");
}
}
fclose(outputFile);

return 0;
}
}
105 changes: 105 additions & 0 deletions hand/Hand.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#include <string.h>
#include "Hand.h"

static unsigned char white[] = {255, 255, 255};
static unsigned char black[] = {0, 0, 0};
static unsigned char red[] = {255, 0, 0};
static unsigned char green[] = {0, 255, 0};
//static unsigned char blue[] = {0, 0, 255};
//static unsigned char magenta[] = {255, 0, 255};
static unsigned char yellow[] = {255, 255, 0};
//static unsigned char cyan[] = {0, 255, 255};

Hand::Hand()
{
mLeft = -1;
mRight = -1;
mTop = -1;
mBottom = -1;
memset(mPostureColors, 0, NUM_HAND_COLORS * sizeof(const char *));
}

Hand::~Hand()
Expand Down Expand Up @@ -41,4 +52,98 @@ string Hand::GetPostureString()
void Hand::SetPostureString(const string& postureStr)
{
mPostureStr = postureStr;

if ( postureStr == POSTURE_CLOSED_STR )
{
mPostureColors[0] = white;
mPostureColors[1] = white;
mPostureColors[2] = white;
mPostureColors[3] = white;
}
else if ( postureStr == POSTURE_POINT_STR )
{
mPostureColors[0] = black;
mPostureColors[1] = white;
mPostureColors[2] = white;
mPostureColors[3] = white;
}
else if ( postureStr == POSTURE_TWO_STR )
{
mPostureColors[0] = white;
mPostureColors[1] = black;
mPostureColors[2] = white;
mPostureColors[3] = white;
}
else if ( postureStr == POSTURE_THREE_STR )
{
mPostureColors[0] = black;
mPostureColors[1] = black;
mPostureColors[2] = white;
mPostureColors[3] = white;
}
else if ( postureStr == POSTURE_FOUR_STR )
{
mPostureColors[0] = white;
mPostureColors[1] = white;
mPostureColors[2] = black;
mPostureColors[3] = white;
}
else if ( postureStr == POSTURE_OPEN_STR )
{
mPostureColors[0] = black;
mPostureColors[1] = white;
mPostureColors[2] = black;
mPostureColors[3] = white;
}
else if ( postureStr == POSTURE_FIST_STR )
{
mPostureColors[0] = green;
mPostureColors[1] = green;
mPostureColors[2] = green;
mPostureColors[3] = green;
}
else if ( postureStr == POSTURE_THUMB_STR )
{
mPostureColors[0] = black;
mPostureColors[1] = green;
mPostureColors[2] = green;
mPostureColors[3] = green;
}
else if ( postureStr == POSTURE_PINKY_STR )
{
mPostureColors[0] = green;
mPostureColors[1] = green;
mPostureColors[2] = green;
mPostureColors[3] = black;
}
else if ( postureStr == POSTURE_VULCAN_STR )
{
mPostureColors[0] = yellow;
mPostureColors[1] = white;
mPostureColors[2] = white;
mPostureColors[3] = yellow;
}
else if ( postureStr == POSTURE_HANGLOOSE_STR )
{
mPostureColors[0] = black;
mPostureColors[1] = green;
mPostureColors[2] = green;
mPostureColors[3] = yellow;
}
else
{
// Unknown posture string
mPostureColors[0] = red;
mPostureColors[1] = red;
mPostureColors[2] = red;
mPostureColors[3] = red;
}
}

const unsigned char* Hand::GetPostureColor(int colorNum)
{
if ( (colorNum < 0) || (colorNum >= NUM_HAND_COLORS) )
return 0;

return mPostureColors[colorNum];
}
16 changes: 16 additions & 0 deletions hand/Hand.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
#include <string>
using std::string;

#define NUM_HAND_COLORS 4

#define POSTURE_CLOSED_STR "closed"
#define POSTURE_FIST_STR "fist"
#define POSTURE_FOUR_STR "four"
#define POSTURE_HANGLOOSE_STR "hangloose"
#define POSTURE_OPEN_STR "open"
#define POSTURE_PINKY_STR "pinky"
#define POSTURE_POINT_STR "point"
#define POSTURE_THREE_STR "three"
#define POSTURE_THUMB_STR "thumb"
#define POSTURE_TWO_STR "two"
#define POSTURE_VULCAN_STR "vulcan"

class Hand
{
public:
Expand All @@ -13,12 +27,14 @@ class Hand
bool SetBounds(int left, int right, int top, int bottom);
string GetPostureString();
void SetPostureString(const string& postureStr);
const unsigned char* GetPostureColor(int colorNum);
private:
int mLeft;
int mRight;
int mTop;
int mBottom;
string mPostureStr;
const unsigned char* mPostureColors[NUM_HAND_COLORS];
};

#endif
Loading

0 comments on commit 30ee5f4

Please sign in to comment.