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

时间:2015-01-21 14:52:38

标签: c++ opencv visual-studio-2013 face-detection

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

#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;
}

目前我收到此错误:

  

错误1错误LNK2019:未解析的外部符号&#34; public:__ cdecl cv :: CascadeClassifier :: CascadeClassifier(void)&#34; (?? 0CascadeClassifier @ cv @@ QEAA @ XZ)在函数main

中引用

需要帮助解决问题。

1 个答案:

答案 0 :(得分:0)

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/