正如我在my previous question中所提到的,我无法通过Viola - Jones算法获得有关检测面部特征的准确结果。特别是在单独和口中获得眼睛时,它不能很好地工作。但是检测面部,眼睛对和鼻子没有问题。所以我想到了一个简单的算法,它是:
在检测对象时,我使用 cvHaarDetectObjects 方法。但是使用这种方法,看起来不可能在所需像素之间搜索对象。那么有一些功能,如" 获取此图像,并搜索x和y之间的鼻子,x +宽度和y +高度像素,并给我鼻子的坐标。&# 34;
任何有用的帮助。
答案 0 :(得分:0)
我找到了答案。没有必要在期望的像素之间进行搜索。 Viola - Jones算法已经像上面的简单算法那样找到了特征。因此,如果您按顺序搜索对象,它会毫无问题地找到面部特征。这是一个示例代码:
void Detection::Detect()
{
FacialFeatures* facialFeatures = new FacialFeatures();
DrawRectangle(DetectFeature(faceDetector));
DrawRectangle(DetectFeature(eyesDetector));
DrawRectangle(DetectFeature(noseDetector));
DrawRectangle(DetectFeature(mouthDetector));
DrawRectangle(DetectFeature(leftEyeDetector));
DrawRectangle(DetectFeature(righteyeDetector));
}
CvRect* Detection::DetectFeature(const char* detectorType)
{
pCascade_ = (CvHaarClassifierCascade* ) cvLoad(detectorType,0,0,0);
pRectSeq_ = cvHaarDetectObjects(pImage_, pCascade_, pStorage_, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING, cvSize(20,20));
CvRect* r = (CvRect*) cvGetSeqElem(pRectSeq_,0);
return r;
}
void Detection::DrawRectangle(CvRect* r)
{
cvNamedWindow("Detected", CV_WINDOW_AUTOSIZE);
CvPoint pt1 = { r->x, r->y };
CvPoint pt2 = { r->x + r->width, r->y + r->height };
cvRectangle(pImage_, pt1, pt2, CV_RGB(0,255,0), 3, 4, 0);
cvShowImage("Detected", pImage_);
cvWaitKey(0);
}