Move the sources to trunk
[opencv] / cvaux / src / cvfacedetection.h
1 // FaceDetection.h: interface for the FaceDetection class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #ifndef _CVFACEDETECTION_H_
6 #define _CVFACEDETECTION_H_
7
8 #include "cvfacetemplate.h"
9 #include "cvface.h"
10 #include "cvboostingtemplate.h"
11
12 typedef struct CvContourRect
13 {
14         int             iNumber;  //ïîðÿäêîâûé íîìåð àòðèáóòà
15         int             iType;    //òèï îáúåêòà
16         int             iFlags;   //ñâîáîäíîå ïîëå
17         CvSeq   *seqContour; //àäðåñ íà÷àëà çàïèñè îáúåêòà 
18         int             iContourLength;  //äëèíà çàïèñè âåêòîðîâ
19         CvRect  r;    //îïèñàíûé ïðÿìîóãîëüíèê
20         CvPoint pCenter; // center of rect
21         int             iColor;//    öâåò çàïîëíåíèÿ êîíòóðà
22 } CvContourRect;
23
24 //class Face;
25
26 class ListElem
27 {
28 public:
29         ListElem();
30         ListElem(Face * pFace,ListElem * pHead);
31         virtual ~ListElem();
32         ListElem * m_pNext;
33         ListElem * m_pPrev;
34         Face * m_pFace;
35 };//class ListElem
36
37 class List
38 {
39 public:
40         List();
41         int AddElem(Face * pFace);
42         virtual ~List();
43         Face* GetData();
44         long m_FacesCount;
45 private:
46         ListElem * m_pHead;
47         ListElem * m_pCurElem;
48 };//class List
49
50
51 class FaceDetection  
52 {
53 public:
54         void FindFace(IplImage* img);
55         void CreateResults(CvSeq * lpSeq);
56         FaceDetection();
57         virtual ~FaceDetection();
58         void SetBoosting(bool bBoosting) {m_bBoosting = bBoosting;}
59         bool isPostBoosting() {return m_bBoosting;}
60 protected:
61
62         IplImage* m_imgGray;
63         IplImage* m_imgThresh;
64         int m_iNumLayers;
65         CvMemStorage* m_mstgContours;
66         CvSeq* m_seqContours[MAX_LAYERS];
67         CvMemStorage* m_mstgRects;
68         CvSeq* m_seqRects;
69         
70         bool m_bBoosting;
71         List * m_pFaceList;
72
73 protected:
74         void ResetImage();
75         void FindContours(IplImage* imgGray);
76         void AddContours2Rect(CvSeq*  seq, int color, int iLayer);
77         void ThresholdingParam(IplImage* imgGray, int iNumLayers, int& iMinLevel, int& iMaxLevel, int& iStep);
78         void FindCandidats();
79         void PostBoostingFindCandidats(IplImage * FaceImage);
80 };
81
82 inline void ReallocImage(IplImage** ppImage, CvSize sz, long lChNum)
83 {
84     IplImage* pImage;
85     if( ppImage == NULL ) 
86                 return;
87     pImage = *ppImage;
88     if( pImage != NULL )
89     {
90         if (pImage->width != sz.width || pImage->height != sz.height || pImage->nChannels != lChNum)
91             cvReleaseImage( &pImage );
92     }
93     if( pImage == NULL )
94         pImage = cvCreateImage( sz, IPL_DEPTH_8U, lChNum);
95     *ppImage = pImage;
96 };
97
98
99
100 #endif // !defined(AFX_FACEDETECTION_H__55865033_D8E5_4DD5_8925_34C2285BB1BE__INCLUDED_)