www.pudn.com > 人体步态跟踪识别bate版.rar > Human.cpp
// Human.cpp: implementation of the CHuman class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "humantrack.h" #include "Human.h" #include "math.h" #include#ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CHuman::CHuman() { SetHeadRegion(); if(m_JointPoint.GetSize()!=0) { m_JointPoint.RemoveAll(); } m_JointPoint.Add(m_head.Point); SetNeckRegion(); m_JointPoint.Add(m_neck.Point); SetChestRegion(); SetAbdomenRegion(); SetRightUpperArm(); SetRightLowerArm(); SetLeftUpperArm(); SetLeftLowerArm(); SetLeftThighRegion(); SetRightThighRegion(); SetLeftCrusRegion(); SetRightCrusRegion(); SetLeftFootRegion(); SetRightFootRegion(); SetRightHand(); SetLeftHand(); } CHuman::~CHuman() { } void CHuman::DrawHuman(CDC* pDC) { CPoint* Pos=new CPoint[4]; CPen pen(PS_SOLID,2,RGB(255,0,0)); pDC->SelectObject(&pen); pDC->SetROP2(R2_MASKPEN); //绘制头部 RectangleRotation(m_head,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制颈部 RectangleRotation(m_neck,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制胸部 RectangleRotation(m_chest,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制腹部 RectangleRotation(m_abdomen,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制右上臂 RectangleRotation(m_right_upper_arm,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制右前臂 RectangleRotation(m_right_lower_arm,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制右手 RectangleRotation(m_right_hand,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制左上臂 RectangleRotation(m_left_upper_arm,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制左下臂 RectangleRotation(m_left_lower_arm,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制左手 RectangleRotation(m_left_hand,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制左大腿 RectangleRotation(m_left_thigh,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制左小腿 RectangleRotation(m_left_crus,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制左脚 RectangleRotation(m_left_foot,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制右大腿 RectangleRotation(m_right_thigh,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制右小腿 RectangleRotation(m_right_crus,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); //绘制右脚 RectangleRotation(m_right_foot,Pos); pDC->MoveTo(*(Pos)); pDC->LineTo(*(Pos+1)); pDC->LineTo(*(Pos+2)); pDC->LineTo(*(Pos+3)); pDC->LineTo(*(Pos)); delete Pos; } //设置头部区域 void CHuman::SetHeadRegion() { m_head.Point.x=155; m_head.Point.y=384-34; m_head.Angle=0; m_head.Height=26; m_head.Width=26; } //设置颈部区域 void CHuman::SetNeckRegion() { m_neck.Point.x=152; m_neck.Point.y=384-48; m_neck.Angle=360-30; m_neck.Height=8; m_neck.Width=16; } //设置左上臂 void CHuman::SetLeftUpperArm() { m_left_upper_arm.Angle=96; m_left_upper_arm.Point.x=154; m_left_upper_arm.Point.y=384-68; m_left_upper_arm.Height=8; m_left_upper_arm.Width=34; } //设置左下臂 void CHuman::SetLeftLowerArm() { m_left_lower_arm.Angle=126; m_left_lower_arm.Height=8; m_left_lower_arm.Width=34; m_left_lower_arm.Point.x=160; m_left_lower_arm.Point.y=384-100; } //设置右上臂 void CHuman::SetRightUpperArm() { m_right_upper_arm.Angle=76; m_right_upper_arm.Point.x=136; m_right_upper_arm.Point.y=384-66; m_right_upper_arm.Height=8; m_right_upper_arm.Width=34; } //设置右下臂 void CHuman::SetRightLowerArm() { m_right_lower_arm.Angle=78; m_right_lower_arm.Point.x=128; m_right_lower_arm.Point.y=384-96; m_right_lower_arm.Height=6; m_right_lower_arm.Width=28; } //设置右手 void CHuman::SetRightHand() { m_right_hand.Angle=78; m_right_hand.Point.x=124; m_right_hand.Point.y=384-116; m_right_hand.Height=10; m_right_hand.Width=12; } //设置左手 void CHuman::SetLeftHand() { m_left_hand.Angle=120; m_left_hand.Point.x=174; m_left_hand.Point.y=384-116; m_left_hand.Height=10; m_left_hand.Width=12; } //设置胸部区域 void CHuman::SetChestRegion() { m_chest.Angle=0; m_chest.Point.x=146; m_chest.Point.y=384-70; m_chest.Height=36; m_chest.Width=26; } //设置腹部区域 void CHuman::SetAbdomenRegion() { m_abdomen.Angle=0; m_abdomen.Point.x=146; m_abdomen.Point.y=384-104; m_abdomen.Height=32; m_abdomen.Width=26; } //设置左大腿区域 void CHuman::SetLeftThighRegion() { m_left_thigh.Angle=70; m_left_thigh.Point.x=138; m_left_thigh.Point.y=384-138; m_left_thigh.Height=18; m_left_thigh.Width=42; } //设置右大腿区域 void CHuman::SetRightThighRegion() { m_right_thigh.Angle=120; m_right_thigh.Point.x=156; m_right_thigh.Point.y=384-136; m_right_thigh.Height=18; m_right_thigh.Width=42; } //设置左小腿区域 void CHuman::SetLeftCrusRegion() { m_left_crus.Angle=70; m_left_crus.Point.x=122; m_left_crus.Point.y=384-176; m_left_crus.Height=14; m_left_crus.Width=38; } //设置右小腿区域 void CHuman::SetRightCrusRegion() { m_right_crus.Angle=118; m_right_crus.Point.x=174; m_right_crus.Point.y=384-172; m_right_crus.Height=14; m_right_crus.Width=38; } //设置左脚区域 void CHuman::SetLeftFootRegion() { m_left_foot.Angle=0; m_left_foot.Point.x=120; m_left_foot.Point.y=384-198; m_left_foot.Height=12; m_left_foot.Width=32; } //设置右脚区域 void CHuman::SetRightFootRegion() { m_right_foot.Angle=30; m_right_foot.Point.x=194; m_right_foot.Point.y=384-196; m_right_foot.Height=12; m_right_foot.Width=30; } void CHuman::ComputerRegin(Region r, RECT prect) { } //绕一点的矩形旋转 void CHuman::Rotation(CPoint* p1,CPoint p0,double angle) { double R_x=0; double R_y=0; double Angle1=0; Angle1=(angle*3.1416)/180.0; R_x=(p1->x-p0.x)*cos(Angle1)-(p1->y-p0.y)*sin(Angle1); R_y=(p1->y-p0.y)*cos(Angle1)+(p1->x-p0.x)*sin(Angle1); p1->x=R_x+p0.x; p1->y=R_y+p0.y; } void CHuman::RectangleRotation(Region r, CPoint *p) { CPoint leftup(0,0); CPoint rightup(0,0); CPoint leftdown(0,0); CPoint rightdown(0,0); leftup.x=r.Point.x-r.Width/2; leftup.y=(r.Point.y-r.Height/2); Rotation(&leftup,r.Point,r.Angle); rightup.x=r.Point.x+r.Width/2; rightup.y=(r.Point.y-r.Height/2); Rotation(&rightup,r.Point,r.Angle); leftdown.x=r.Point.x-r.Width/2; leftdown.y=(r.Point.y+r.Height/2); Rotation(&leftdown,r.Point,r.Angle); rightdown.x=r.Point.x+r.Width/2; rightdown.y=(r.Point.y+r.Height/2); Rotation(&rightdown,r.Point,r.Angle); (p+0)->x=leftup.x; (p+0)->y=384-leftup.y; (p+1)->x=rightup.x; (p+1)->y=384-rightup.y; (p+2)->x=rightdown.x; (p+2)->y=384-rightdown.y; (p+3)->x=leftdown.x; (p+3)->y=384-leftdown.y; }