Skip to content

Commit

Permalink
segmentation improvements and trainer argument changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yodergj committed Jul 29, 2015
1 parent b7a4fef commit 3f3d3c4
Show file tree
Hide file tree
Showing 13 changed files with 595 additions and 63 deletions.
2 changes: 2 additions & 0 deletions HandyMouse/HandyMouse/HandyMouse.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
<ClCompile Include="..\..\geometry\Point.cpp" />
<ClCompile Include="..\..\geometry\Rect.cpp" />
<ClCompile Include="..\..\hand\HandyTracker.cpp" />
<ClCompile Include="..\..\image\Color.cpp" />
<ClCompile Include="..\..\image\ColorRegion.cpp" />
<ClCompile Include="..\..\image\ConnectedRegion.cpp" />
<ClCompile Include="..\..\image\Image.cpp" />
Expand Down Expand Up @@ -234,6 +235,7 @@
<ClInclude Include="..\..\geometry\Point.h" />
<ClInclude Include="..\..\geometry\Rect.h" />
<ClInclude Include="..\..\hand\HandyTracker.h" />
<ClInclude Include="..\..\image\Color.h" />
<ClInclude Include="..\..\image\ColorRegion.h" />
<ClInclude Include="..\..\image\ConnectedRegion.h" />
<ClInclude Include="..\..\image\Image.h" />
Expand Down
6 changes: 6 additions & 0 deletions HandyMouse/HandyMouse/HandyMouse.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
<ClCompile Include="..\..\xmlutils\XMLUtils2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\image\Color.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="handymouse.h">
Expand Down Expand Up @@ -168,5 +171,8 @@
<ClInclude Include="..\..\xmlutils\XMLUtils2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\image\Color.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
7 changes: 4 additions & 3 deletions HandyMouse/HandyMouse/handymouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ HandyMouse::~HandyMouse()

void HandyMouse::BuildImageFilter()
{
QString filter;
QString filter = "PNG files (*.png);;";
QList<QByteArray> formats = QImageWriter::supportedImageFormats();
foreach (QString format, formats)
{
filter += QString("%1 files (*.%2);;").arg(format.toUpper()).arg(format);
if ( format.toUpper() != QString("PNG") )
filter += QString("%1 files (*.%2);;").arg(format.toUpper()).arg(format);
}
if (filter.endsWith(";;"))
filter.chop(2);
Expand Down Expand Up @@ -107,7 +108,7 @@ void HandyMouse::on_actionLoad_triggered()
QString filename = QFileDialog::getOpenFileName(this,
tr("Open Video"),
"",
tr("Video Files (*.asf *.wma *.wmv *.divx *.f4v *.flv *.mkv *.mk3d *.mka *.mks *.mcf *.mp4 *.mpg *.mpeg *.ogg *.ogv *.mov *.qt *.webm)"));
tr("Video Files (*.asf *.wma *.wmv *.divx *.f4v *.flv *.mkv *.mk3d *.mka *.mks *.mcf *.mp4 *.mpg *.mpeg *.mts *.ogg *.ogv *.mov *.qt *.webm)"));

if ( filename.isEmpty() )
return;
Expand Down
2 changes: 2 additions & 0 deletions HandyTrainer/HandyTrainer/HandyTrainer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<ClCompile Include="..\..\geometry\Point.cpp" />
<ClCompile Include="..\..\geometry\Rect.cpp" />
<ClCompile Include="..\..\hand\HandyTracker.cpp" />
<ClCompile Include="..\..\image\Color.cpp" />
<ClCompile Include="..\..\image\ColorRegion.cpp" />
<ClCompile Include="..\..\image\ConnectedRegion.cpp" />
<ClCompile Include="..\..\image\Image.cpp" />
Expand All @@ -113,6 +114,7 @@
<ClInclude Include="..\..\geometry\Point.h" />
<ClInclude Include="..\..\geometry\Rect.h" />
<ClInclude Include="..\..\hand\HandyTracker.h" />
<ClInclude Include="..\..\image\Color.h" />
<ClInclude Include="..\..\image\ColorRegion.h" />
<ClInclude Include="..\..\image\ConnectedRegion.h" />
<ClInclude Include="..\..\image\Image.h" />
Expand Down
6 changes: 6 additions & 0 deletions HandyTrainer/HandyTrainer/HandyTrainer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
<ClCompile Include="..\..\xmlutils\XMLUtils2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\image\Color.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\image\ColorRegion.h">
Expand Down Expand Up @@ -134,5 +137,8 @@
<ClInclude Include="..\..\xmlutils\XMLUtils2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\image\Color.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
71 changes: 54 additions & 17 deletions HandyTrainer/HandyTrainer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "ColorRegion.h"
#include "HandyTracker.h"

#define MIN_REGION_WIDTH 75
#define MIN_REGION_HEIGHT 75

int main(int argc, char *argv[])
{
#if 0
Expand All @@ -18,19 +21,21 @@ int main(int argc, char *argv[])
int width, height;
int numWeakClassifiers;
int classIndex = 0;
string className;
string className, listFilename;
Image image;
VideoDecoder* videoDecoder = new VideoDecoder;
AdaboostClassifier handClassifier;
HandyTracker tracker;
char filename[256];
char filename[512];
char buf[1024];
FILE *file;
int revNumber = 0;
std::vector<double> aspectRatios;

if ( argc < 6 )
if ( argc != 4 )
{
printf("Usage: %s <class name> <num weak classifiers> <hand class Image> [...] -x <hand non-class image> [...]\n", argv[0]);
//printf("Usage: %s <class name> <num weak classifiers> <hand class Image> [...] -x <hand non-class image> [...]\n", argv[0]);
printf("Usage: %s <class name> <num weak classifiers> <list file>\n", argv[0]);
return 0;
}

Expand All @@ -39,37 +44,62 @@ int main(int argc, char *argv[])
numWeakClassifiers = atoi(argv[2]);
if ( numWeakClassifiers < 1 )
{
printf("Invalid number of weak classifiers %d\n", numWeakClassifiers );
fprintf(stderr, "Invalid number of weak classifiers %d\n", numWeakClassifiers );
return 1;
}

listFilename = argv[3];
FILE* listFp = fopen(listFilename.c_str(), "r");
if ( !listFp )
{
fprintf(stderr, "Failed opening list file <%s>\n", listFilename.c_str());
return 1;
}
std::vector<std::string> fileVec;
while ( fgets(buf, 1024, listFp) && !feof(listFp) )
{
std::string str = buf;
if ( str.empty() )
continue;

while ( (str[str.size() - 1] == '\n') ||
(str[str.size() - 1] == '\r') )
{
str = str.substr(0, str.size() - 1);
}

if ( !str.empty() )
fileVec.push_back(str);
}
fclose(listFp);

if ( !handClassifier.Create(HandyTracker::mNumFeatures, 2, numWeakClassifiers) )
{
printf("Failed creating classifier\n");
fprintf(stderr, "Failed creating classifier\n");
return 1;
}

std::string featureStr("abcdefghijklmnopq");
handClassifier.SetFeatureString(featureStr);

for (i = 3; i < argc; i++)
for (i = 0; i < (int)fileVec.size(); i++)
{
if ( !strcmp(argv[i], "-x") )
if ( !strcmp(fileVec[i].c_str(), "-x") )
{
classIndex = 1;
continue;
}
if ( image.Load(argv[i]) )
if ( image.Load(fileVec[i]) )
{
if ( classIndex == 0 )
printf("Processing hand class image %s\n", argv[i]);
printf("Processing hand class image %s\n", fileVec[i].c_str());
else
printf("Processing other hand image %s\n", argv[i]);
printf("Processing other hand image %s\n", fileVec[i].c_str());
width = image.GetWidth();
height = image.GetHeight();
Point startPt(width / 2, height / 2);
ColorRegion region;
if ( region.Grow(image, startPt) )
if ( region.Grow(image, startPt) && (region.GetWidth() >= MIN_REGION_WIDTH) && (region.GetHeight() >= MIN_REGION_HEIGHT) )
{
Matrix featureData;
if ( tracker.GenerateFeatureData(&region, featureData) )
Expand All @@ -82,13 +112,13 @@ int main(int argc, char *argv[])
}
else
{
videoDecoder->SetFilename(argv[i]);
videoDecoder->SetFilename(fileVec[i]);
if ( videoDecoder->Load() )
{
if ( classIndex == 0 )
printf("Processing hand class video %s\n", argv[i]);
printf("Processing hand class video %s\n", fileVec[i].c_str());
else
printf("Processing other hand video %s\n", argv[i]);
printf("Processing other hand video %s\n", fileVec[i].c_str());

int frameNumber = 0;
ColorRegion* oldRegion = 0;
Expand Down Expand Up @@ -118,7 +148,14 @@ int main(int argc, char *argv[])
fprintf(stderr, "Failed growing color region\n");
}

if ( !region->Empty() )
if ( (region->GetWidth() < MIN_REGION_WIDTH) || (region->GetHeight() < MIN_REGION_HEIGHT) )
{
fprintf(stderr, "Rejecting color region for minimum size\n");
delete region;
region = oldRegion;
oldRegion = 0;
}
else
{
Matrix featureData;
if ( tracker.GenerateFeatureData(region, featureData) )
Expand All @@ -138,7 +175,7 @@ int main(int argc, char *argv[])
delete region;
}
else
fprintf(stderr, "Failed opening image/video %s\n", argv[i]);
fprintf(stderr, "Failed opening image/video %s\n", fileVec[i].c_str());

delete videoDecoder;
videoDecoder = new VideoDecoder;
Expand Down
7 changes: 7 additions & 0 deletions geometry/Point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@ bool Point::operator<(const Point& ref) const
if ( y != ref.y )
return (y < ref.y);
return (x < ref.x);
}

int Point::GetTaxicabDistance(const Point& ref)
{
int xdist = abs(x - ref.x);
int ydist = abs(y - ref.y);
return xdist + ydist;
}
18 changes: 18 additions & 0 deletions geometry/Point.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef _POINT_H
#define _POINT_H

#include <float.h>
#include <math.h>
#include <utility>
class DoublePoint;

class Point
Expand All @@ -16,8 +19,23 @@ class Point
bool operator!=(const Point& ref) const;
bool operator<(const Point& ref) const;

int GetTaxicabDistance(const Point& ref);

int x;
int y;
};

typedef std::pair<double, Point> DistPointPair;

class DistPointPairCompare
{
public:
bool operator()(const DistPointPair& l, const DistPointPair& r)
{
if ( fabs(l.first - r.first) > FLT_MIN )
return (l.first < r.first);
return (l.second < r.second);
}
};

#endif
2 changes: 1 addition & 1 deletion hand/HandyTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ bool HandyTracker::AnalyzeRegion(ColorRegion* region)

bool HandyTracker::AnalyzeRegionForInitialization(ColorRegion* region)
{
if ( !region || !mOpenClassifier || !mClosedClassifier )
if ( !region )
return false;

// If we're missing a classifier, just do the regular analysis
Expand Down
Loading

0 comments on commit 3f3d3c4

Please sign in to comment.