www.pudn.com > stlreader.rar > Foot.cpp
// Foot.cpp: implementation of the CFoot class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "twoimage.h"
#include "Foot.h"
#include "CDib.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFoot::CFoot()
{
}
CFoot::~CFoot()
{
delete []m_SideImage;
delete []m_UpImage;
delete []m_SideColorImage;
delete []m_UpColorImage;
delete []m_maxZ;
delete []m_minZ;
delete []m_maxY;
delete []m_minY;
}
/////////此函数找到鞋的长度,图像为第一副图
int CFoot::FindLength(BYTE *Img, int nWidth, int nHeigth)
{
int i,j,k;
int l,minx =0,maxx =0,maxl =0,miny =0,maxy =0;
for(i=0;i127&&isfirst)
{
minx =j;
//m_origex =minx;
miny =i;
isfirst=false;
}
if(Img[i*nWidth+j]>127&&maxx<=j)
{
maxx =j;
}
}
l = maxx- minx;
if(maxl<=l)
{
maxl =l;
m_origex = minx;
m_origez = miny;
m_footlength =l;
}
}
//Img[2*nWidth+2] =255;
//Img[2*nWidth+200] =255;
//m_footlength =m_footlength;
return(0);
}
/////////////此函数根据鞋的长度找到鞋的高度,存放在m_footheith中
void CFoot::FindHeigth(BYTE *Img, int nWidth, int nHeigth)
{
int i,j,k;
i =(int)(m_footlength*0.66+m_origex);
int maxy =0,miny=0;
bool isfirst =true;
for(j=0;j127)
{
if(maxy<=j)
maxy =j;
if(isfirst)
{
miny =j;
isfirst =false;
}
}
}
m_footheith =maxy-miny;
}
////此处的Img为脚的正面图,根据正面图找出鞋的最大宽度
void CFoot::Findwidth(BYTE *Img, int nWidth, int nHeigth)
{
int i,j,k;
int l,minx =0,maxx =0,maxl =0,miny =0,maxy =0;
int zuixiafang =0;//最下方的点
int zuizuofang;
for(i=0;i127&&isfirst)
{ if(zuixiafang ==0)
{
zuixiafang =i;
zuizuofang =j;
}
minx =j;
//m_origex =minx;
miny =i;
isfirst=false;
}
if(Img[i*nWidth+j]>127&&maxx<=j)
{
maxx =j;
}
}
l = maxx- minx;
if(maxl<=l)
{
maxl =l;
m_origex2 = minx;
m_origey2 = miny;
m_footwidth =l;
}
//第二副图的原点在第m_origex2列,m_origey2行
}
//Img[2*nWidth+2] =255;
//Img[2*nWidth+200] =255;
//m_footlength =m_footlength;
m_origey2 =zuixiafang;
m_origex2 =zuizuofang;
}
void CFoot::FindmaxminY()
{
int i,j,k;
BYTE *Img =m_UpImage;
int nWidth =m_UpWidth;
int nHeigth = m_UpHeigth;
int isfirst =1 ;
//memset(isfirst,1,(m_footlength)*sizeof(int));
m_minY =new int[m_footlength];
memset(m_minY,0,(m_footlength)*sizeof(int));
m_maxY =new int[m_footlength];
//memset(m_maxY,0,(m_footlength)*sizeof(int));
for( i=0;i127)
{ if(isfirst)
{
m_minY[i-m_origey2] =j-100;
m_maxY[i-m_origey2] =m_minY[i-m_origey2]+1;
}
else
{
m_maxY[i-m_origey2] =j-100;
}
isfirst=0;
}
}
}
if(m_maxY[i]127)
{
if(isfirst[i])
{
m_minZ[i] = j-m_origez;
isfirst[i] =0;
}
else
{
m_maxZ[i] =j-m_origez;
m_maxZ[i] =m_maxZ[i]+0;
}
}
}
delete [] isfirst;
}
void CFoot::Init(CString PictrueFile1,CString PictrueFile2)
{
CFile f1;
f1.Open(PictrueFile1,CFile::modeRead,NULL );
CDib dib1;
dib1.Read(&f1);
m_UpWidth =dib1.GetDimensions().cx;
m_UpHeigth = dib1.GetDimensions().cy;
m_UpColorImage =new BYTE[m_UpWidth*m_UpHeigth*3];
m_UpColorImage =dib1.m_lpImage;
CFile f2;
f2.Open(PictrueFile2,CFile::modeRead,NULL );
CDib dib2;
dib2.Read(&f2);
m_SideWidth =dib2.GetDimensions().cx;
m_SideHeigth = dib2.GetDimensions().cy;
m_SideColorImage =new BYTE[m_SideWidth*m_SideHeigth*3];
m_SideColorImage =dib2.m_lpImage;
Color2Gray();
Sobeledge(m_UpImage,m_UpWidth,m_UpHeigth,2);
Sobeledge(m_SideImage,m_SideWidth,m_SideHeigth,1);
FindLength(m_SideImage,m_SideWidth, m_SideHeigth);
FindHeigth(m_SideImage,m_SideWidth, m_SideHeigth);
Findwidth( m_UpImage,m_UpWidth, m_UpHeigth);
FindmaxminZ();
FindmaxminY();
//int xxx =m_footlength;
f1.Close();
f2.Close();
Find100WH();
}
//DEL void CFoot::PreImage()
//DEL {
//DEL
//DEL }
void CFoot::Sobeledge(BYTE *Img, int nWidth, int nHeigth,int index)
{ int i,j;
BYTE *A=new BYTE[nWidth*nHeigth];
int nVertical,nLevel;
double X;
double threld;
int Dx[]={-1,-2,-1,0,0,0,1,2,1};
int Dy[]={-1,0,1,-2,0,2,-1,0,1};
for(i=0;ithreld)
A[i*nWidth+j]=255;
else
A[i*nWidth+j]=0;
if(i<30||i>180||j>300||j<30)//用在第一只脚上,sobel域值为40
A[i*nWidth+j]=0;
}
else
{
threld =120;
if(X>threld)
A[i*nWidth+j]=255;
else
A[i*nWidth+j]=0;
if(i<10||i>220||j>200||j<30)//用在第二只脚上,sobel域值为120
A[i*nWidth+j]=0;
}
}
}
for(i=0;im_footlength)
index =m_footlength;
m_Width[i] =(float)(m_maxY[index] -m_minY[index])/259*240;
m_Heigth[i] =(float)(m_maxZ[index]-m_minZ[index])/259*240;
m_Heigth[i] =m_Heigth[i]+0;
}
}