64,637
社区成员
发帖
与我相关
我的任务
分享
const string frontalface="D:\\study\\opencv\\data\\lbpcascades\\lbpcascade_frontalface.xml";
const string profileface="D:\\study\\opencv\\data\\haarcascades\\haarcascade_profileface.xml";
const string lefteye="D:\\study\\opencv\\data\\haarcascades\\haarcascade_mcs_lefteye.xml";
const string righteye="D:\\study\\opencv\\data\\haarcascades\\haarcascade_mcs_righteye.xml";
const string nose="D:\\study\\opencv\\data\\haarcascades\\haarcascade_mcs_nose.xml";
const string mouth="D:\\study\\opencv\\data\\haarcascades\\haarcascade_mcs_mouth.xml";
cv::CascadeClassifier facedetect;
facedetect.load(frontalface);
fd.SetConfiguration(frontalface, profileface,lefteye,righteye,nose,mouth,VO_AdditiveStrongerClassifier::BOOSTING,CFaceDetectionAlgs::FRONTAL );
void CFaceDetectionAlgs::SetConfiguration( const string& strfrontalface,
const string& strprofileface,
const string& strlefteye,
const string& strrighteye,
const string& strnose,
const string& strmouth,
unsigned int mtd,
unsigned int facetype)
{
switch(this->m_iDetectionMethod)
{
case VO_AdditiveStrongerClassifier::BOOSTING:
default:
{
if(strfrontalface!="")
{
//this->m_sFile2BLoadFrontalFace = strfrontalface;
this->m_cascadeClassifierFrontalFace.load( strfrontalface);
}
}
}
//this->m_sFile2BLoadFrontalFace = strfrontalface;
#ifndef __VO_FACEDETECTIONALGS_H__
#define __VO_FACEDETECTIONALGS_H__
#include <string>
#include "opencv2/opencv.hpp"
#include "VO_CVCommon.h"
#include "VO_FaceCompPos.h"
#include "VO_DetectionAlgs.h"
using namespace std;
using namespace cv;
/**
* @author JIA Pei
* @brief Face detection algorithms.
*/
class CFaceDetectionAlgs : public CDetectionAlgs
{
private:
/** Original detected face rectangle */
vector<Rect> m_vDetectedFaceRects;
/** Detected face type:
0 - no face detected; 1 - frontal; 2 - left; 3 - right */
unsigned int m_iFaceType;
/** Whether .... is detected */
bool m_bFaceDetected;
bool m_bLeftEyeDetected;
bool m_bRightEyeDetected;
bool m_bNoseDetected;
bool m_bMouthDetected;
/** Possible windows for further face parts detection */
Rect m_CVLeftEyePossibleWindow;
Rect m_CVRightEyePossibleWindow;
Rect m_CVNosePossibleWindow;
Rect m_CVMouthPossibleWindow;
Rect m_CVNoseCentralArea;
/** Detected windows for respective face parts */
// haven't translated back to the whole image yet
VO_FaceCompPos m_VOFaceComponents0;
VO_FaceCompPos m_VOFaceComponents;
Rect m_CVDetectedFaceWindow2SM;
Mat m_CVDetectedFaceImagePatch2SM;
/** Detected Key Points */
Point2f m_CVDetectedCenterOfGravity;
Point2f m_CVDetectedLeftEyeLeftCorner;
Point2f m_CVDetectedLeftEyeRightCorner;
Point2f m_CVDetectedLeftEyeCenter;
Point2f m_CVDetectedRightEyeLeftCorner;
Point2f m_CVDetectedRightEyeRightCorner;
Point2f m_CVDetectedRightEyeCenter;
Point2f m_CVDetectedNoseTip;
Point2f m_CVDetectedNostrilLeft;
Point2f m_CVDetectedNostrilRight;
Point2f m_CVDetectedNoseCenter;
Point2f m_CVDetectedMouthLeftCorner;
Point2f m_CVDetectedMouthRightCorner;
Point2f m_CVDetectedMouthCenter;
string m_sFile2BLoadFrontalFace;
string m_sFile2BLoadProfileFace;
string m_sFile2BLoadLeftEye;
string m_sFile2BLoadRightEye;
string m_sFile2BLoadNose;
string m_sFile2BLoadMouth;
string m_sFile2BLoadMouthBeard;
CascadeClassifier m_cascadeClassifierFrontalFace;
CascadeClassifier m_cascadeClassifierProfileFace;
CascadeClassifier m_cascadeClassifierEyes;
CascadeClassifier m_cascadeClassifierLeftEye;
CascadeClassifier m_cascadeClassifierRightEye;
CascadeClassifier m_cascadeClassifierNose;
CascadeClassifier m_cascadeClassifierMouth;
CascadeClassifier m_cascadeClassifierMouthBeard;
CascadeClassifier m_cascadeClassifier;
RTreeClassifier m_rtreeClassifierFrontalFace;
RTreeClassifier m_rtreeClassifierProfileFace;
RTreeClassifier m_rtreeClassifierEyes;
RTreeClassifier m_rtreeClassifierLeftEye;
RTreeClassifier m_rtreeClassifierRightEye;
RTreeClassifier m_rtreeClassifierNose;
RTreeClassifier m_rtreeClassifierMouth;
RTreeClassifier m_rtreeClassifierMouthBeard;
/** Initialization */
void init(const string& str, unsigned int mtd)
{
CDetectionAlgs::init(str, mtd);
this->m_vDetectedFaceRects.clear();
this->m_iFaceType = UNDETECTED;
this->m_bFaceDetected = false;
this->m_bLeftEyeDetected = false;
this->m_bRightEyeDetected = false;
this->m_bNoseDetected = false;
this->m_bMouthDetected = false;
}
public:
CascadeClassifier m_cascadeClassifierpublic;
/** frontal face, left profile face, right profile face, etc. */
enum {
FRONTAL = 0,
LEFTPROFILE = 1,
RIGHTPROFILE = 2,
UPPROFILE = 3,
DOWNPROFILE = 4,
ALL = 9
};
/** face directions */
enum {
UNDETECTED = -1,
DIR_DOWNFRONTAL = 0,
DIR_DOWNLEFT = 1,
DIR_DOWNRIGHT = 2,
DIR_UPFRONTAL = 3,
DIR_UPLEFT = 4,
DIR_UPRIGHT = 5,
DIR_FRONTAL = 6,
DIR_LEFT = 7,
DIR_RIGHT = 8
};
/** Constructor */
CFaceDetectionAlgs( const string& str="",
unsigned int mtd=
VO_AdditiveStrongerClassifier::BOOSTING)
{
this->init(str, mtd);
}
/** Destructor */
~CFaceDetectionAlgs() {}
/** set detection configurations */
void SetConfiguration( const string& strfrontalface="",
const string& strprofileface="",
const string& strlefteye="",
const string& strrighteye="",
const string& strnose="",
const string& strmouth="",
unsigned int mtd =
VO_AdditiveStrongerClassifier::BOOSTING,
unsigned int facetype = FRONTAL);
};
#endif // __VO_FACEDETECTIONALGS_H__
CPP文件为:
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "VO_FacePart.h"
#include "VO_FaceKeyPoint.h"
#include "VO_FaceDetectionAlgs.h"
void CFaceDetectionAlgs::SetConfiguration( const string& strfrontalface,
const string& strprofileface,
const string& strlefteye,
const string& strrighteye,
const string& strnose,
const string& strmouth,
unsigned int mtd,
unsigned int facetype)
{
this->m_iDetectionMethod = mtd;
this->m_iFaceType = facetype;
switch(this->m_iDetectionMethod)
{
case VO_AdditiveStrongerClassifier::BAGGING:
{
if(strfrontalface!="")
{
//this->m_sFile2BLoadFrontalFace = strfrontalface;
//this->m_rtreeClassifierProfileFace.read( this->m_sFile2BLoadFrontalFace.c_str() );
this->m_rtreeClassifierProfileFace.read( strfrontalface.c_str() );
}
if(strprofileface!="")
{
this->m_sFile2BLoadProfileFace = strprofileface;
this->m_rtreeClassifierProfileFace.read( this->m_sFile2BLoadProfileFace.c_str() );
}
if(strlefteye!="")
{
this->m_sFile2BLoadLeftEye = strlefteye;
this->m_rtreeClassifierLeftEye.read( this->m_sFile2BLoadLeftEye.c_str() );
}
if(strrighteye!="")
{
this->m_sFile2BLoadRightEye = strrighteye;
this->m_rtreeClassifierRightEye.read( this->m_sFile2BLoadRightEye.c_str() );
}
if(strnose!="")
{
this->m_sFile2BLoadNose = strnose;
this->m_rtreeClassifierNose.read( this->m_sFile2BLoadNose.c_str() );
}
if(strmouth!="")
{
this->m_sFile2BLoadMouth = strmouth;
this->m_rtreeClassifierMouth.read( this->m_sFile2BLoadMouth.c_str() );
}
}
break;
case VO_AdditiveStrongerClassifier::BOOSTING:
default:
{
if(strfrontalface!="")
{
//this->m_sFile2BLoadFrontalFace = strfrontalface;
cv::CascadeClassifier facedetect;
facedetect.load(strfrontalface);
//m_cascadeClassifierpublic.load(strfrontalface);
m_cascadeClassifier.load(strfrontalface);
m_cascadeClassifierFrontalFace.load( strfrontalface);
}
if(strprofileface!="")
{
//this->m_sFile2BLoadProfileFace = strprofileface;
//this->m_cascadeClassifierProfileFace.load( this->m_sFile2BLoadProfileFace );
this->m_cascadeClassifierProfileFace.load( strprofileface );
}
if(strlefteye!="")
{
//this->m_sFile2BLoadLeftEye = strlefteye;
//this->m_cascadeClassifierLeftEye.load( this->m_sFile2BLoadLeftEye );
this->m_cascadeClassifierLeftEye.load( strlefteye );
}
if(strrighteye!="")
{
//this->m_sFile2BLoadRightEye = strrighteye;
//this->m_cascadeClassifierRightEye.load( this->m_sFile2BLoadRightEye );
this->m_cascadeClassifierRightEye.load( strrighteye );
}
if(strnose!="")
{
//this->m_sFile2BLoadNose = strnose;
//this->m_cascadeClassifierNose.load( this->m_sFile2BLoadNose );
this->m_cascadeClassifierNose.load( strnose );
}
if(strmouth!="")
{
//this->m_sFile2BLoadMouth = strmouth;
//this->m_cascadeClassifierMouth.load( this->m_sFile2BLoadMouth );
this->m_cascadeClassifierMouth.load( strmouth );
}
}
break;
}
}
string m_sFile2BLoadFrontalFace;
就是string变量啊CascadeClassifier m_cascadeClassifierFrontalFace;
这个是opencv里面的,我之前定义了这个测试了这个传进去的参数,没有什么问题啊
cv::CascadeClassifier facedetect;
facedetect.load(frontalface);