2015-06-18 2 views
0

Я в настоящее время изменяю facerec_demo из OpenCV, и я получаю следующие ошибки при компиляции моего кода.Ошибка связывания библиотек OpenCV

Creating library C:\Users\L\op_models\20nodes.project\20nodes-scenario1.dev64.i0.nt.lib and object C:\Users\L\op_models\20nodes.project\20nodes-scenario1.dev64.i0.nt.exp 
wlan_mac_hcf.dev64.i0.pr.obj : error LNK2019: unresolved external symbol "class cv::Ptr<class cv::FaceRecognizer> __cdecl cv::createFisherFaceRecognizer(int,double)" ([email protected]@@[email protected]@[email protected]@@[email protected]@Z) referenced in function "void __cdecl faceRecognition(struct _IplImage *,char *,char *,double *,double *,double (* const)[2])" ([email protected]@[email protected]@[email protected]) 
wlan_mac_hcf.dev64.i0.pr.obj : error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" ([email protected]@@[email protected]) referenced in function "public: __cdecl cv::Mat::Mat(class cv::Mat const &)" ([email protected]@@[email protected]@@Z) 
C:\Users\L\op_models\20nodes.project\20nodes-scenario1.dev64.i0.nt.dll : fatal error LNK1120: 2 unresolved externals 
Microsoft (R) Manifest Tool version 5.2.3790.2076 

Я знаю, что эта проблема обычно возникает, когда вы забыли включить библиотеку в опции компоновщика, поэтому я дважды проверил мои настройки и они заключаются в следующем:

/LIBPATH:C:\OpenCV2.4\opencv\build\x64\vc9\lib 
opencv_calib3d240.lib 
opencv_contrib240.lib 
opencv_core240.lib 
opencv_features2d240.lib 
opencv_flann240.lib 
opencv_gpu240.lib 
opencv_haartraining_engine.lib 
opencv_highgui240.lib 
opencv_imgproc240.lib 
opencv_legacy240.lib 
opencv_ml240.lib 
opencv_nonfree240.lib 
opencv_objdetect240.lib 
opencv_photo240.lib 
opencv_stitching240.lib 
opencv_ts240.lib 
opencv_video240.lib 
opencv_videostab240.lib 

Я не верю что я пропустил файлы библиотеки, поэтому я не уверен, что может вызвать проблему; вот мой код для справки. Извините за беспорядок, это все еще продолжается.

#include "opencv2\core\core.hpp" 
#include "opencv2\contrib\contrib.hpp" 
#include "opencv2\highgui\highgui.hpp" 
#include "opencv2\imgproc\imgproc.hpp" 
#include "opencv2\objdetect\objdetect.hpp" 

void faceRecognition(IplImage* img, char * in,char * d,double *accu, double *error,double truthArray[][2]) 
{ 
    using namespace cv; 
// Get the path to your CSV: 
//string fn_haar = cascade);  // we don't need to load the xml because it is a global assigned elsewhere. 
std::string fn_csv = "faces.csv"; 

// These vectors hold the images and corresponding labels: 
std::vector<cv::Mat> images; 
std::vector<int> labels; 

// Read in the data (fails if no valid input filename is given, but you'll get an error message): 
try 
{ 
    read_csv(fn_csv, images, labels); 
} 
catch (cv::Exception& e) 
{ 
    return; 
} 

// Get the height from the first image. We'll need this 
// later in code to reshape the images to their original 
// size AND we need to reshape incoming faces to this size: 
int im_width = images[0].cols; 
int im_height = images[0].rows; 

// Create a FaceRecognizer and train it on the given images: 
Ptr<FaceRecognizer> model = createFisherFaceRecognizer(); 
model->train(images, labels); 

// That's it for learning the Face Recognition model. You now 
// need to create the classifier for the task of Face Detection. 
// We are going to use the haar cascade you have specified in the 
// command line arguments: 

cv::CascadeClassifier haar_cascade; 
//load the xml global assigned elsewhere 
haar_cascade.load(cascade_name); 

// convert input image into Mat format 
cv::Mat frame(img); 

// Clone the current frame: 
cv::Mat original = frame.clone(); 
// Convert the current frame to grayscale: 
cv::Mat gray; 
cvtColor(original, gray, CV_BGR2GRAY); 
// Find the faces in the frame: 
std::vector< cv::Rect_<int> > faces; 
haar_cascade.detectMultiScale(gray, faces); 
// At this point you have the position of the faces in 
// faces. Now we'll get the faces, make a prediction and 
// annotate it in the video. Cool or what? 
for(int i = 0; i < faces.size(); i++) 
{ 
    // Process face by face: 
    cv::Rect face_i = faces[i]; 
    // Crop the face from the image. So simple with OpenCV C++: 
    cv::Mat face = gray(face_i); 
    // Resizing the face is necessary for Eigenfaces and Fisherfaces. You can easily 
    // verify this, by reading through the face recognition tutorial coming with OpenCV. 
    // Resizing IS NOT NEEDED for Local Binary Patterns Histograms, so preparing the 
    // input data really depends on the algorithm used. 
    // 
    // I strongly encourage you to play around with the algorithms. See which work best 
    // in your scenario, LBPH should always be a contender for robust face recognition. 
    // 
    // Since I am showing the Fisherfaces algorithm here, I also show how to resize the 
    // face you have just found: 
    cv::Mat face_resized; 
    cv::resize(face, face_resized, cv::Size(im_width, im_height), 1.0, 1.0, cv::INTER_CUBIC); 
    // Now perform the prediction, see how easy that is: 
    int prediction = model->predict(face_resized); 
    // And finally write all we've found out to the original image! 
    // First of all draw a green rectangle around the detected face: 
    rectangle(original, face_i, CV_RGB(0, 255,0), 1); 
    // Create the text we will annotate the box with: 
    std::string box_text = cv::format("Prediction = %d", prediction); 

    // Calculate the position for annotated text (make sure we don't 
    // put illegal values in there): 
    int pos_x = std::max(face_i.tl().x - 10, 0); 
    int pos_y = std::max(face_i.tl().y - 10, 0); 
    // And now put it into the image: 

} 

ответ

0

Из того, что я вижу из ваших библиотек, я считаю, что вы забыли включить библиотеку лиц, найденную в opencv_contrib.

Библиотека должна быть построена как отдельная сущность и включена в вышеупомянутый компоновщик. https://github.com/Itseez/opencv_contrib

После того, как вы построите эту библиотеку, вы найдете новый .lib/.a содержащий слово face. Это тот, который вы хотите связать своим проектом.

В качестве побочного примечания я в настоящее время работаю над проектом распознавания лиц с использованием алгоритма EigenFaces, и это похоже на мой cmake.

find_package(OpenCV COMPONENTS core highgui face REQUIRED)

Этого достаточно, чтобы сделать работу алгоритма с обучающим и вашим тестовым набором.

Кроме того, добавив все библиотеки в свой проект, вы значительно увеличите время и размер вашей библиотеки.

Надеюсь, что это поможет,