Ask Your Question
0

Eigenfaces face recognizer gives error: unresolved external symbols

asked 2012-12-03 06:52:06 -0600

KBregnhoved gravatar image

Hej - I'm having probems with making the Eigenface-part of this turtorial: http://docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html#eigenfaces

When I try to run it I get these errors:

1>main.obj : error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::subspaceReconstruct(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputArray const &)" (?subspaceReconstruct@cv@@YA?AVMat@1@ABV_InputArray@1@00@Z) referenced in function __catch$_main$0 1>main.obj : error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::subspaceProject(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputArray const &)" (?subspaceProject@cv@@YA?AVMat@1@ABV_InputArray@1@00@Z) referenced in function __catch$_main$0 1>main.obj : error LNK2019: unresolved external symbol "void __cdecl cv::applyColorMap(class cv::_InputArray const &,class cv::_OutputArray const &,int)" (?applyColorMap@cv@@YAXABV_InputArray@1@ABV_OutputArray@1@H@Z) referenced in function __catch$_main$0 1>main.obj : error LNK2019: unresolved external symbol "class cv::Ptr<class cv::facerecognizer=""> __cdecl cv::createEigenFaceRecognizer(int,double)" (?createEigenFaceRecognizer@cv@@YA?AV?$Ptr@VFaceRecognizer@cv@@@1@HN@Z) referenced in function __catch$_main$0

Is there someone who can help me with this? I cannot figure out what I'm doing wrong...

The actual code look like this:

#include "opencv2/core/core.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <fstream>
using namespace cv;
using namespace std;    
// Function, which creates a normalized image

static Mat norm_0_255(InputArray _src) {
    Mat src = _src.getMat();
    // Create and return normalized image:
    Mat dst;
    switch(src.channels()) {
    case 1:
    cv::normalize(_src, dst, 0, 255, NORM_MINMAX, CV_8UC1);
    break;
case 3:
    cv::normalize(_src, dst, 0, 255, NORM_MINMAX, CV_8UC3);
    break;
default:
    src.copyTo(dst);
    break;
}
return dst;
}        

// Reads the csv-file in, which includes the images from the image-database:        


static void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, char separator = ';') {
//
std::ifstream file(filename.c_str(), ifstream::in);
// If there is no file, then it comes out with an error message:
if (!file) {
    string error_message = "No valid input file was given, please check the given filename.";
    CV_Error(CV_StsBadArg, error_message);
}
string line, path, classlabel;
// As long as there is lines in the file, the program takes in the next line in the csv-file:
while (getline(file, line)) {
    stringstream liness(line);
    getline(liness, path, separator);
    getline(liness, classlabel);
    // If there is no more lines:
    if(!path.empty() && !classlabel.empty()) {
        images.push_back(imread(path, 0));
        labels.push_back(atoi(classlabel.c_str()));
    }
}
 }        


int main(int argc, const char *argv[]) {
// Check for valid command line arguments, print usage
// if no arguments were given.
if (argc < 2) {
    //cout this and exit the program
    cout << "usage: " << argv[0] << " <csv.ext> <output_folder> " << endl;
    exit(1);
}
string output_folder;
// if there are 3 arguments given:
if (argc == 3) {
    output_folder = string(argv[2]);
   }        


// Get the path to the CSV-file.
string fn_csv = string(argv[1]); //"...\attFaceDatabaseText.csv"; 

// These vectors hold the images and corresponding labels.
vector<Mat> images;
vector<int> labels;

// Read in the data. This can fail if no valid ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-12-10 14:05:26 -0600

updated 2012-12-10 14:07:12 -0600

It looks like you are having a linker error. Did you link against the necessary libraries for the sample, which are:

  • opencv_core
  • opencv_contrib
  • opencv_imgproc
  • opencv_highgui

If you look into:

You'll see, that all of the samples can be built with a simple CMakeLists.txt. Only the following lines are relevant for you:

## Only to make sure our CMake installation 
## has the OpenCV plugin on board:
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

## Just to give the project a name:
project(facerec_cpp_samples)

## If you didn't install OpenCV into a system-wide
## search directory, you probably need to uncomment
## this (to give CMake a hint, where to search for 
## your OpenCV installation):
#SET(OpenCV_DIR /path/to/your/opencv/installation)

## This searches for your OpenCV installation and
## sets the include pathes accordingly 
find_package(OpenCV REQUIRED) 

## We'll build an executable "facerec_eigenfaces" from
## the facerec_eigenfaces.cpp. This project just consist 
## of this single source file:
add_executable(facerec_eigenfaces facerec_eigenfaces.cpp)

## And finally link against the necessary libraries. Chances
## are good, that you missed this in your setup:
target_link_libraries(facerec_eigenfaces opencv_contrib opencv_core opencv_imgproc opencv_highgui)

Just a hint: You can also build Visual Studio project files with CMake. But if you don't feel comfortable with CMake, then have a look at the tutorials on how to setup OpenCV:

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-12-03 06:52:06 -0600

Seen: 3,517 times

Last updated: Dec 10 '12