C ++ opencv人脸检测

时间:2014-01-12 09:01:25

标签: c++ visual-studio-2010 opencv face-recognition

我正在编写一个应该使用C ++检测面部的小脚本, 我在visual studio 2010上开发。

附上相关方法, 我得到以下异常,我不明白:

"opencvVisualization.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall cv::CascadeClassifier::~CascadeClassifier(void)" (??1CascadeClassifier@cv@@UAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'cascade_eye''(void)" (??__Fcascade_eye@@YAXXZ)" 

任何帮助都会非常感激。

#include "opencvVisualization.h"
#include "main.h"
#include <cstdio>
#include <highgui.h>
#include <cv.h>
#include <iostream>

using namespace cv;
using namespace std; 

CvRect *r;

const string haarcascade_face = "C:\\haarcascades\\haarcascade_frontalface_alt.xml";
const string haarcascade_eye = "C:\\haarcascades\\haarcascade_eye.xml";

CvHaarClassifierCascade* cascade;
CvMemStorage* storage;
CascadeClassifier cascade_face, cascade_eye;
char c;

void detectAndDisplay( IplImage* img);

void prepareCascade();

boolean isFaceImage (IplImage * image);

void prepareCascade() {
cascade = (CvHaarClassifierCascade*)cvLoad("C:\\haarcascades\\haarcascade_frontalface_alt.xml");
CvCapture *capture = 0;
cascade_face.load(haarcascade_face);
cascade_eye.load(haarcascade_eye);
}

boolean isFaceImage (IplImage * image) {
     CvSeq* faces = cvHaarDetectObjects(image, cascade, storage, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING, cvSize (100, 100));
     int i;

    for(i = 0; i<(faces ? faces->total:0); i++)
    {

         r=(CvRect*)cvGetSeqElem(faces,i);
         cvRectangle(image,
                     cvPoint(r->x, r->y),
                     cvPoint(r->x + r->width, r->y + r->height),
                     CV_RGB(255,0,0), 1, 8, 0);
                     }
    return (i>0); 
}

/* **************************************************************************************** */

1 个答案:

答案 0 :(得分:0)

问题解决了。

我删除了不必要的CascadeClassifiers, 并使用

将内存分配给存储
storage = cvCreateMemStorage(0);

足以根据需要运行人脸检测算法