OpenCV 未定义的体系结构符号 x86_64:lineDescriptor

OpenCV Undefined symbols for architecture x86_64: lineDescriptor

我从源代码构建了 OpenCV 以及 opencv_contrib

出于某种原因,我在 lineDescriptor 中访问 类 的所有尝试都会导致链接器错误。

所有这些声明都会引发链接器错误

BinaryDescriptor bsd = BinaryDescriptor();
Ptr<BinaryDescriptor> bsd1 = BinaryDescriptor::createBinaryDescriptor();
Ptr<LSDDetector> lsd1 = LSDDetector::createLSDDetector();

我完全理解这个错误的意思,但我不知道为什么首先抛出它。

我环顾四周并尝试了不同的解决方案; changing the compiler, and linked my libraries,但错误仍然存​​在。

#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/line_descriptor.hpp"

using namespace cv;
using namespace std;
using namespace line_descriptor;

void detectLines(Mat& original, Mat grey)
{
    Ptr<LineSegmentDetector> lsd = createLineSegmentDetector(2);

    vector<Vec4f> lines;

    lsd->detect(grey, lines);

    cout << "Detected " << lines.size() << endl;

    lsd->drawSegments(original, lines);

    // Linker problems galore
//  BinaryDescriptor bsd = BinaryDescriptor();
//  Ptr<BinaryDescriptor> bsd1 = BinaryDescriptor::createBinaryDescriptor();
//  Ptr<LSDDetector> lsd1 = LSDDetector::createLSDDetector();

}

这些是我当前的链接器标志

-lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab

我个人觉得这与我的旗帜有关,但我不确定 lineDescriptor 对应的旗帜。任何帮助将不胜感激!

来自README on opencv_contrib's GitHub

to run, linker flags to contrib modules will need to be added to use them in your code/IDE. For example to use the aruco module, "-lopencv_aruco" flag will be added.

所以你只需要 link 带有标志

contrib 模块 line_descriptor
-lopencv_line_descriptor

这是一个 thorough answer on SO,它会在安装步骤中一次 link 遍历所有库。