使用 visual studio 在 opencv 中运行人脸检测时出现错误 LNK2019

error LNK2019 while runing face detection in opencv using visual studio

我正在尝试使用代码来检测图像中的人脸。我从网上尝试了以下示例代码。

#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

int main(int argc, const char** argv)
{
//create the cascade classifier object used for the face detection
CascadeClassifier face_cascade;
//use the haarcascade_frontalface_alt.xml library
face_cascade.load("haarcascade_frontalface_alt.xml");

//setup video capture device and link it to the first capture device
VideoCapture captureDevice;
captureDevice.open(0);

//setup image files used in the capture process
Mat captureFrame;
Mat grayscaleFrame;

//create a window to present the results
namedWindow("outputCapture", 1);

//create a loop to capture and find faces
while (true)
{
    //capture a new image frame
    captureDevice >> captureFrame;

    //convert captured image to gray scale and equalize
    cvtColor(captureFrame, grayscaleFrame, CV_BGR2GRAY);
    equalizeHist(grayscaleFrame, grayscaleFrame);

    //create a vector array to store the face found
    std::vector<Rect> faces;

    //find faces and store them in the vector array
    face_cascade.detectMultiScale(grayscaleFrame, faces, 1.1, 3, CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_SCALE_IMAGE, Size(30, 30));

    //draw a rectangle for all found faces in the vector array on the original image
    for (int i = 0; i < faces.size(); i++)
    {
        Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
        Point pt2(faces[i].x, faces[i].y);

        rectangle(captureFrame, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8, 0);
    }

    //print the output
    imshow("outputCapture", captureFrame);

    //pause for 33ms
    waitKey(33);
}
return 0;
}

目前我遇到这个错误:

Error 1 error LNK2019: unresolved external symbol "public: __cdecl cv::CascadeClassifier::CascadeClassifier(void)" (??0CascadeClassifier@cv@@QEAA@XZ) referenced in function main

需要帮助解决问题。

cv::CascadeClassifier::CascadeClassifier(void) 构造函数调用似乎不存在。在此处查看 openCV 文档 -

http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html

似乎是链接问题。检查你是否有类似这里的问题

http://answers.opencv.org/question/9421/cascade-classifier-for-eye-detection-errors-while-compiling/