-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHairFace.cpp
More file actions
77 lines (69 loc) · 2.12 KB
/
HairFace.cpp
File metadata and controls
77 lines (69 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//////////////////////////////////////////////////////////////////////
// HairFace.cpp: 类CHairFace接口
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "FaceDetect.h"
#include "HairFace.h"
//////////////////////////////////////////////////////////////////////
// 构造函数/析构函数
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// 构造函数
// 参数: source-原始数据
// width-图像宽度
// height-图像高度
//////////////////////////////////////////////////////////////////////
CHairFace::CHairFace(RGBQUAD ** source,int width,int height)
{
m_nWidth = width;
m_nHeight= height;
m_bBinaryOK = false;
m_pSourceData = source;
m_pBinaryArray = new BYTE*[height];
for(int i=0;i <height; i++)
m_pBinaryArray[i] = new BYTE[width];
}
//////////////////////////////////////////////////////////////////////
// 析构函数
//////////////////////////////////////////////////////////////////////
CHairFace::~CHairFace()
{
if(m_pBinaryArray!=NULL)
{
for(int i=0;i<m_nHeight;i++)
if(m_pBinaryArray[i]!=NULL) delete m_pBinaryArray[i];
delete m_pBinaryArray;
}
}
//////////////////////////////////////////////////////////////////////
// 标记脸和头发的位置
//////////////////////////////////////////////////////////////////////
void CHairFace::MarkHairFace()
{
int i,j;
for(i=0;i<m_nHeight;i++)
for(j=0;j<m_nWidth ;j++)
{
double r,g,Y,temp;
temp = m_pSourceData[i][j].rgbGreen
+m_pSourceData[i][j].rgbRed
+m_pSourceData[i][j].rgbBlue;
r = (double)m_pSourceData[i][j].rgbRed/temp;
g = (double)m_pSourceData[i][j].rgbGreen/temp;
Y = 0.30*m_pSourceData[i][j].rgbRed+0.59*m_pSourceData[i][j].rgbGreen
+0.11*m_pSourceData[i][j].rgbBlue;
if(g<0.398 && g > 0.246 && r<0.664 && r>0.333 && r>g && g>=0.5*(1-r))
{
m_pBinaryArray[i][j] = 0; //脸的位置
}
else if(Y<40)
{
m_pBinaryArray[i][j] = 1; //头发位置
}
else
{
m_pBinaryArray[i][j] = 2; //什么也不是
}
}
m_bBinaryOK = true;
}