www.pudn.com > Gesture[20040824].rar > HandGesture.cpp
// HandGesture.cpp: implementation of the CHandGesture class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Gesture.h"
#include "HandGesture.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CHandGesture::CHandGesture(CBackground *bkg, CSkinColor *skincolor)
{
background = bkg;
skin = skincolor;
Th_Kcurv = -10;
Th_Kstep = 35;
m_bFindChange = false;
m_HandBin = NULL;
ContourStorage = cvCreateMemStorage(0);
}
CHandGesture::~CHandGesture()
{
if ( m_HandBin != NULL ) delete m_HandBin;
}
void CHandGesture::Initialize(int width, int height)
{
if ( m_HandBin != NULL ) delete m_HandBin;
m_HandBin = new CImage;
m_HandBin->Create(width, height, 8);
}
void CHandGesture::ExtractHandRegion( IplImage *HandImage )
{
}
void CHandGesture::ExtractStatisticFeatures()
{
}
void CHandGesture::ExtractContourFeatures()
{
}
void CHandGesture::ExtractMaxLenContour( CvSeq *Contours, CvSeq **MaxContour )
{
}
void CHandGesture::ExtractHandTips(CvSeq *contour, int step)
{
}
int CHandGesture::CalculateKCurvature(CvPoint pFor, CvPoint pMid, CvPoint pBack)
{
return 0;
}
void CHandGesture::DrawStatisticFeaturesToImage(IplImage *image)
{
int scale = 2;
int color;
if (image->nChannels>1)
color = CV_RGB(255,255,255);
else color = 255;
CvPoint center;
CvStatisticFeatures *pSF = GetStatisticHandFeatures();
center.x = (int)pSF->center.x;
center.y = (int)pSF->center.y;
cvCircle(image, center, 3, color, 2);
float offsetX = pSF->size.width*cos(pSF->angle)/(2*scale);
float offsetY = pSF->size.width*sin(pSF->angle)/(2*scale);
CvPoint p1, p2;
p1.x = (int)(center.x-offsetX);
p1.y = (int)(center.y-offsetY);
p2.x = (int)(center.x+offsetX);
p2.y = (int)(center.y+offsetY);
cvLine(image, p1, p2, color,1);
offsetX = pSF->size.height*cos(pSF->angle+Pi/2)/(2*scale);
offsetY = pSF->size.height*sin(pSF->angle+Pi/2)/(2*scale);
p1.x = (int)(center.x-offsetX);
p1.y = (int)(center.y-offsetY);
p2.x = (int)(center.x+offsetX);
p2.y = (int)(center.y+offsetY);
cvLine(image, p1, p2, color, 1);
}
void CHandGesture::DrawContourFeaturesToImage(IplImage *image)
{
int color;
if (image->nChannels>1)
color = CV_RGB(255,255,255);
else color = 255;
CvContourFeatures *pCF = GetContourHandFeatures();
for(int i=0; inTips; i++)
cvCircle(image, pCF->FingerTips[i], 5, color, 2);
for( i=0; inRoots; i++)
cvCircle(image, pCF->FingerRoots[i], 5, color, 4);
}