我必须用我的数据库训练Viola-Jones算法以获得准确的结果吗? [英] Do I have to train Viola-Jones Algorithm with my database to obtain accurate results?

查看:213
本文介绍了我必须用我的数据库训练Viola-Jones算法以获得准确的结果吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试提取面部数据库的面部特征,但我认识到Viola-Jones算法在两种情况下无法正常工作:




  • 当我试图单独检测到眼睛时,

  • 当我尝试检测嘴巴时。



* 效果不佳:检测图像的不同部分为眼睛或嘴巴。或者有时检测到其中几个是不可能的情况。



Detection.cpp b

  #includeDetection.h

检测::检测(const char * imagePath,const char * detectorType)
{
pImage_ = cvLoadImage(imagePath,CV_LOAD_IMAGE_COLOR);
pStorage_ = cvCreateMemStorage(0);
pCascade_ =(CvHaarClassifierCascade *)cvLoad(detectorType,0,0,0);

if(!pImage_ ||!pStorage_ ||!pCascade_)
{
std :: cout< 加载图像的问题< std :: endl;
exit(-1);
}

//检测图像中的面值
pFaceRectSeq_ = cvHaarDetectObjects(pImage_,pCascade_,pStorage_,1.1,3,CV_HAAR_DO_CANNY_PRUNING,cvSize(0,0));
//创建一个窗口显示检测到的面
cvNamedWindow(Detected,CV_WINDOW_AUTOSIZE);

//每次检测时绘制一个矩形轮廓
for(int i = 0; i <(pFaceRectSeq_?pFaceRectSeq _-> total:0); i ++)

CvRect * r =(CvRect *)cvGetSeqElem(pFaceRectSeq_,0);
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);
}

// r可以作为功能集保存到文件/数据库

cvShowImage(Detected,pImage_);
cvWaitKey(0);
}

Detection ::〜Detection()
{
cvDestroyWindow(Detected);
cvReleaseImage(& pImage_);
if(pCascade_)
cvReleaseHaarClassifierCascade(& pCascade_);
if(pStorage_)
cvReleaseMemStorage(& pStorage_);
}

void检测:: SaveFaceFeatures(char * fileName)
{

}

main.cpp:

  #include< iostream> 
#includeDetection.h

const char * imagePath =C:/1.jpg;
const char * faceDetector =C:/opencv/data/haarcascades/haarcascade_frontalface_default.xml;
const char * eyesDetector =C:/opencv/data/haarcascades/haarcascade_mcs_eyepair_big.xml;
const char * righteyeDetector =C:/opencv/data/haarcascades/haarcascade_mcs_righteye.xml;
const char * leftEyeDetector =C:/opencv/data/haarcascades/haarcascade_mcs_lefteye.xml;
const char * noseDetector =C:/opencv/data/haarcascades/haarcascade_mcs_nose.xml;
const char * mouthDetector =C:/opencv/data/haarcascades/haarcascade_mcs_mouth.xml;

int main(int argc,char * argv [])
{
检测* face = new检测(imagePath,faceDetector);
//face->SaveFaceFeatures(\"01-1mFeatures.txt);
检测* eyes = new检测(imagePath,eyesDetector);
//检测* rightEye =新检测(imagePath,righteyeDetector);
//检测* leftEye =新检测(imagePath,leftEyeDetector);
检测* nose = new检测(imagePath,noseDetector);
//检测* mouth = new检测(imagePath,mouthDetector);
return 0;
}

我正在使用,




  • haarcascade_mcs_righteye.xml 用于右眼检测,

  • haarcascade_mcs_lefteye.xml <检测


我必须用我的数据库训练算法?是否有可能解决这个问题没有训练的算法?如果不是我可以用AdaBoost训练它?

解决方案

这将更好地搜索眼睛元素),而不是整个图像。您可以在opencv的文件夹中找到示例:



opencv\samples\cpp\tutorial_code\objectDetection\



我建议你去使用新的API。您使用的API已过时,今后将不再支持。


I try to extract facial features of a face database but I recognized that Viola-Jones algorithm is not working well* in two cases:

  • When I try to detect the eyes singly,
  • When I try to detect the mouth.

*Not working well: Detects different parts of the image as eyes or mouth. Or sometimes detects several of them which is an impossible case. The images I'm using have pure green background and contains a person's frontal face.

Detection.cpp:

#include "Detection.h"

Detection::Detection(const char* imagePath, const char* detectorType)
{
    pImage_ = cvLoadImage(imagePath, CV_LOAD_IMAGE_COLOR);
    pStorage_ = cvCreateMemStorage(0);
    pCascade_ = (CvHaarClassifierCascade* ) cvLoad(detectorType,0,0,0);

    if(!pImage_ || !pStorage_ || !pCascade_)
    {
        std::cout << "Problem with Loading Image" << std::endl;
        exit(-1);
    }

    // Detect Faces in Image
    pFaceRectSeq_ = cvHaarDetectObjects(pImage_, pCascade_, pStorage_, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0));
    // Create a Window To Display Detected Faces
    cvNamedWindow("Detected", CV_WINDOW_AUTOSIZE);

    // Draw a Rectengular Outline Around Each Detection
    for(int i = 0; i < (pFaceRectSeq_ ? pFaceRectSeq_->total : 0); i++)
    {
        CvRect* r = (CvRect*) cvGetSeqElem(pFaceRectSeq_,0);
        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);
    }

    // r can be saved to a file/database as feature set

    cvShowImage("Detected", pImage_);
    cvWaitKey(0);
}

Detection::~Detection()
{
    cvDestroyWindow("Detected");
    cvReleaseImage(&pImage_);
    if(pCascade_) 
        cvReleaseHaarClassifierCascade(&pCascade_);
    if(pStorage_)
        cvReleaseMemStorage(&pStorage_);
}

void Detection::SaveFaceFeatures(char* fileName)
{

}

main.cpp:

#include <iostream>
#include "Detection.h"

const char* imagePath           = "C:/1.jpg";
const char* faceDetector        = "C:/opencv/data/haarcascades/haarcascade_frontalface_default.xml";
const char* eyesDetector        = "C:/opencv/data/haarcascades/haarcascade_mcs_eyepair_big.xml";
const char* righteyeDetector    = "C:/opencv/data/haarcascades/haarcascade_mcs_righteye.xml";
const char* leftEyeDetector     = "C:/opencv/data/haarcascades/haarcascade_mcs_lefteye.xml";
const char* noseDetector        = "C:/opencv/data/haarcascades/haarcascade_mcs_nose.xml";
const char* mouthDetector       = "C:/opencv/data/haarcascades/haarcascade_mcs_mouth.xml";

int main(int argc, char* argv[])
{
    Detection *face     = new Detection(imagePath, faceDetector);
    //face->SaveFaceFeatures("01-1mFeatures.txt");
    Detection *eyes     = new Detection(imagePath, eyesDetector);
    //Detection *rightEye = new Detection(imagePath, righteyeDetector);
    //Detection *leftEye    = new Detection(imagePath, leftEyeDetector);
    Detection *nose     = new Detection(imagePath, noseDetector);
    //Detection *mouth  = new Detection(imagePath, mouthDetector);
    return 0;
}

I'm using,

  • haarcascade_mcs_righteye.xml for right eye detection,
  • haarcascade_mcs_lefteye.xml for left eye detection
  • haarcascade_mcs_mouth.xml for mouth detection.

Do I have to train the algorithm with my database? Is it possible to fix this problem without training the algorithm? If it is not how can I train it with AdaBoost?

解决方案

It'll be better to search for eyes (and other face elements) in the detected face region, not whole image. You can find example in opencv's folder:

opencv\samples\cpp\tutorial_code\objectDetection\

And I recommend you go to new API. The API you use is obsoleted and will not be supported in future.

这篇关于我必须用我的数据库训练Viola-Jones算法以获得准确的结果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆