How do I resolve the linker error with 'cv::face::LBPHFaceRecognizer' in my OpenCV C++ code?

Unresolved External Source in OPENCV C++ Code with cv::face::LBPHFaceRecognizer.

I have OPENCV code which acts a trainer that takes a directory full of face images. I am running this on OpenCV 4.2.0 with the OPENCV contrib 4.2.0 library. I am also running this on the newest version of Visual Studios.

#include <iostream> 
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <filesystem>
#include <opencv2/opencv.hpp>
#include <opencv2/face.hpp>
#include <opencv2/face/facerec.hpp>
using namespace cv;
using namespace cv::face;
using namespace std;
namespace fs = std::filesystem;

void assurePathExists(const string& path) {
    fs::create_directories(fs::path(path).parent_path());
}

int main() {
    Ptr<LBPHFaceRecognizer> recognizer = LBPHFaceRecognizer::create();
    CascadeClassifier detector;
    detector.load("C:/Users/781932/Downloads/haarcascade_frontalface_default.xml");

    string datasetPath = "C:/Users/781932/Documents/STEMVisageVision";

    vector<Mat> faceSamples;
    vector<int> ids;

    vector<string> imagePaths;
    for (const auto& entry : fs::directory_iterator(datasetPath)) {
        if (entry.is_regular_file()) {
            imagePaths.push_back(entry.path().string());
        }
    }

    for (const auto& imagePath : imagePaths) {
        Mat img = imread(imagePath, IMREAD_GRAYSCALE);
        int id = stoi(fs::path(imagePath).stem().string().substr(1));

        vector<Rect> faces;
        detector.detectMultiScale(img, faces);

        for (const auto& face : faces) {
            faceSamples.push_back(img(face));
            ids.push_back(id);
        }
    }

    recognizer->train(faceSamples, ids);

    string trainerPath = "trainer/trainer.yml";
    assurePathExists(trainerPath);
    recognizer->write(trainerPath);

    return 0;
}

After cleaning and rebuilding the solution in VS, it is pretty apparent that the code itself is fine and has no errors. However, I am getting errors regarding the build.

Build started...
1>------ Build started: Project: 5_30_Trainer, Configuration: Debug x64 ------
1>5_30_Trainer.obj : error LNK2019: **unresolved external symbol "public: static struct cv::Ptr<class cv::face::LBPHFaceRecognizer> __cdecl cv::face::LBPHFaceRecognizer::create(int,int,int,int,double)" (?create@LBPHFaceRecognizer@face@cv@@SA?AU?$Ptr@VLBPHFaceRecognizer@face@cv@@@3@HHHHN@Z) referenced in function main**
1>C:\Users\781932\source\repos\5_30_Trainer\x64\Debug\5_30_Trainer.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "5_30_Trainer.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 9:21 AM and took 02.605 seconds ==========

There seems to be an issue with the the cv::face::LBPHFaceRecognizer class. I presume it's a linker issue, but I do have everything included in the project properties. What is the issue?



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Object oriented programming concepts (OOPs)

Network Error and Timeout on Authorize.net JS