gpt4 book ai didi

c++ - 我是否必须使用我的数据库训练 Viola-Jones 算法以获得准确的结果?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:23:11 27 4
gpt4 key购买 nike

我尝试从面部数据库中提取面部特征,但我发现 Viola-Jones 算法在两种情况下效果不佳*:

  • 当我尝试单独检测眼睛时,
  • 当我尝试检测嘴巴时。

*效果不佳:将图像的不同部分检测为眼睛或嘴巴。或者有时会检测到其中的几个,这是不可能的情况。我使用的图像具有纯绿色背景并包含一个人的正面。

检测.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)
{

}

ma​​in.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;
}

我正在使用,

  • haarcascade_mcs_righteye.xml 用于右眼检测,
  • haarcascade_mcs_lefteye.xml 用于左眼检测
  • haarcascade_mcs_mouth.xml 用于嘴部检测。

我必须用我的数据库训练算法吗?是否可以在不训练算法的情况下解决这个问题?如果不是,我该如何使用 AdaBoost 对其进行训练?

最佳答案

最好在检测到的面部区域而不是整个图像中搜索眼睛(和其他面部元素)。您可以在 opencv 的文件夹中找到示例:

opencv\samples\cpp\tutorial_code\objectDetection\

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

关于c++ - 我是否必须使用我的数据库训练 Viola-Jones 算法以获得准确的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22431348/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com