错误LNK2019:未解析的外部符号“void detectLargestObject(class cv :: Mat const&amp;,class cv :: CascadeClassifier&amp;,class cv :: Rect_ <int>&amp;,int)

时间:2015-12-14 11:09:42

标签: c++ opencv

我正在尝试使用此代码进行面部检测:

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;
}

当我运行代码时,显示此错误,我不知道原因:

  

错误LNK2019:未解析的外部符号“void detectLargestObject(class cv :: Mat const&amp;,class cv :: CascadeClassifier&amp;,class cv :: Rect_&lt; int&gt;&amp;,int)

这是我正在调用的检测功能:

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);
    }
}

1 个答案:

答案 0 :(得分:0)

错误是链接器错误;在这种情况下,链接器无法找到detectLargestObject函数的定义/实现。可能是您没有编译该源文件,或者它已过时。尝试清除/删除输出/目标文件,并使用类似:

g++ -o detectface `pkg-config --cflags opencv` main.cpp detectObject.cpp `pkg-config --libs opencv`