使用Visual Studio在OpenCV中运行人脸检测时出现错误LNK2019

error LNK2019 while runing face detection in opencv using visual studio

本文关键字:检测 LNK2019 错误 Studio Visual OpenCV 运行 使用      更新时间:2023-10-16

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

#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:未解析的外部符号"public: __cdecl cv::CascadeClassifier::CascadeClassifier(void)"(??0CascadeClassifier@cv@@QEAA@XZ) 在函数 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/