0

I'm trying to do face detection using this code :

const char *faceCascadeFilename = "lbpcascade_frontalface.xml";     //  LBP face detector.

const char *windowName = "WebcamFaceRec";   // Name shown in the GUI window.


#include <stdio.h>
#include <vector>
#include <string>
#include <iostream>
#include "detectObject.h" 

#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

int main()
{
    CascadeClassifier faceCascade;
    CascadeClassifier eyeCascade1;
    CascadeClassifier eyeCascade2;
    Rect faceRect;
    VideoCapture videoCapture ("m.mp4");

    cout << "Face Detection ." << endl;
    cout << "Realtime face detection using LBP " << endl;
    cout << "Compiled with OpenCV version " << CV_VERSION << endl << endl;

    // Load the face and 1 or 2 eye detection XML classifiers.
    initDetectors(faceCascade);

    while (1)
    {
        Mat frame;
        videoCapture>> frame;
        detectLargestObject(frame, faceCascade, faceRect);
        if (faceRect.width > 0)
        {
            cout << "Face Detection ." << endl;
        }
        imshow("video", frame);
        // Press 'c' to escape
        if (waitKey(30) == 'c') break;
    }

    waitKey(0);
    return 0;
}

When I run the code this error displayed and I don't know why :

error LNK2019: unresolved external symbol "void detectLargestObject(class cv::Mat const &,class cv::CascadeClassifier &,class cv::Rect_<int> &,int)

this is the function for detection that I'm calling :

void detectLargestObject(const Mat &img, CascadeClassifier &cascade, Rect &largestObject, int scaledWidth)

{
    int flags = CASCADE_FIND_BIGGEST_OBJECT;

    Size minFeatureSize = Size(20, 20);

    float searchScaleFactor = 1.1f;

    int minNeighbors = 4;

    vector<Rect> objects;
    detectObjectsCustom(img, cascade, objects, scaledWidth, flags, minFeatureSize, searchScaleFactor, minNeighbors);
    if (objects.size() > 0) {
        // Return the only detected object.
        largestObject = (Rect)objects.at(0);
    }
    else {
        largestObject = Rect(-1,-1,-1,-1);
    }
}
IInspectable
  • 46,945
  • 8
  • 85
  • 181
Musa
  • 119
  • 2
  • 2
  • 7
  • when I compile it in ubuntu says : undefined reference to void detectLargestObject(const Mat &img, CascadeClassifier &cascade, Rect &largestObject, int scaledWidth) – Musa Dec 14 '15 at 11:38
  • You don't even realize how lucky you are, that your application fails to link. If it did, it would produce inconsistent results, or randomly crash. You are binding a reference (`largestObject`) to a temporary. At any rate, the duplicate question tells you, what's wrong (hint: `Rect` and `Rect_` may be different types). – IInspectable Dec 14 '15 at 12:12
  • is `detectLargestObject` in a different file? – Micka Dec 14 '15 at 12:35
  • yes , it is in another file – Musa Dec 14 '15 at 13:23

1 Answers1

0

The error is a Linker Error; in this case, the linker can not find the definition/implementation of detectLargestObject function. Probably, you are not compiling that source file, or it is outdated. Try cleaning/deleting the output/object files and use something like:

g++ -o detectface `pkg-config --cflags opencv` main.cpp detectObject.cpp `pkg-config --libs opencv`
asif
  • 975
  • 8
  • 16