OpenCV未定义参考:cv :: xfeature2d :: BriefDescriptorExtractor :: create(int,bool)

时间:2019-03-24 07:07:22

标签: opencv c++11 linker computer-vision undefined-reference

我打算使用简短描述符。但我收到此未定义的参考错误。构建代码没有问题。但是链接器给出了错误。请让我知道我错过了什么。预先感谢。

这是代码

#include <iostream>
#include <cmath>
#include "opencv2/opencv.hpp"
#include "opencv2/xfeatures2d.hpp"
#include "harris_corner.h"

using namespace std;

class KeypointDescriptor {

public:

    KeypointDescriptor();

    virtual ~KeypointDescriptor() {}

    void generate_keypoints(HarrisCorner&, cv::Mat&);
    void compute_descriptor(HarrisCorner&, cv::Mat&);

    cv::Ptr<cv::xfeatures2d::BriefDescriptorExtractor> desc_extr = cv::xfeatures2d::BriefDescriptorExtractor::create();
    cv::Mat descriptors;
    vector<cv::KeyPoint> kp;

};

CMakeLists.txt如下

cmake_minimum_required(VERSION 3.5)
project(Harris_Corner_Detector_fromScratch)

IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
ENDIF()

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/build/cmake)

find_package(OpenCV REQUIRED)

add_compile_options(-std=c++11)

include_directories(include
${PROJECT_SOURCE_DIR}/
${PROJECT_SOURCE_DIR}/include/
${OpenCV_INCLUDE_DIRS}
)

add_library(HarrisCorner SHARED src/source_code/harris_corner.cpp)
add_library(KeypointDescriptor SHARED src/source_code/keypoint_descriptor.cpp)

add_executable(find_corner src/find_corner.cpp)
target_link_libraries(find_corner ${OpenCV_LIBS} 
                                    HarrisCorner)

add_executable(stitch_image src/stitch_image.cpp)
target_link_libraries(stitch_image ${OpenCV_LIBS}
                                    HarrisCorner
                                    KeypointDescriptor)

输出如下

-- Configuring done
-- Generating done
-- Build files have been written to: /home/tyagaraja/WPI/ARN/HW/Week10/Harris_Corner_Detector_fromScratch/build
[ 25%] Built target HarrisCorner
[ 50%] Built target KeypointDescriptor
[ 62%] Linking CXX executable stitch_image
libKeypointDescriptor.so: undefined reference to `cv::xfeatures2d::BriefDescriptorExtractor::create(int, bool)'
collect2: error: ld returned 1 exit status
CMakeFiles/stitch_image.dir/build.make:141: recipe for target 'stitch_image' failed
make[2]: *** [stitch_image] Error 1
CMakeFiles/Makefile2:105: recipe for target 'CMakeFiles/stitch_image.dir/all' failed
make[1]: *** [CMakeFiles/stitch_image.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

我正在使用ROS Kinetic默认提供的OpenCV

0 个答案:

没有答案