What does the following code do?

asked 2019-06-17 17:01:40 -0600

I'm trying to compile the lsd_slam_noros package located at : https://github.com/IshitaTakeshi/lsd_...

This package depends on a number of other works such as

  1. openFABmap at
  2. g2o at
  3. OpenCV (ofcourse!)

So far I have encountered various different errors and resolved them using information from the internet (google/stackoverflow/answers_opencv). Now I am stuck at this particular error of conflicting declaration

In file included from /usr/local/include/opencv2/features2d/features2d.hpp:48:0,
                 from /home/pp/June/Milestones/lsd_slam_noros-master/thirdparty/openFabMap/include/bowmsctrainer.hpp:6,
                 from /home/pp/June/Milestones/lsd_slam_noros-master/thirdparty/openFabMap/include/openfabmap.hpp:7,
                 from /home/pp/June/Milestones/lsd_slam_noros-master/lsd_slam/global_mapping/fab_map.cc:22:
/usr/local/include/opencv2/features2d.hpp:231:19: error: conflicting declaration ‘typedef class cv::Feature2D cv::FeatureDetector’
 typedef Feature2D FeatureDetector;
In file included from /home/pp/June/Milestones/lsd_slam_noros-master/lsd_slam/global_mapping/fab_map.cc:3:0:
/home/pp/June/Milestones/lsd_slam_noros-master/global_mapping/fab_map.h:10:7: note: previous declaration as ‘class cv::FeatureDetector’
 class FeatureDetector;

I am able to compile the openFABmap package without any errors.
When compiling the lsd_slam module I am getting the declaration conflict error. I think the error is due to wrong usage in fab_map.cc

I looked in to the source of file fab_map.hpp and it contains the following code :

#pragma once
#include <opencv2/core/core.hpp>

namespace of2 {
class FabMap;
namespace cv {
    class FeatureDetector;
    class BOWImgDescriptorExtractor;

namespace lsd_slam

class Frame;

/** Interface to openFabMap. */
class FabMap
    /** Initializes FabMap. */

    /** Writes out the confusion matrix if enabled. */

    /** Adds the keyframe to the set of frames to compare against and returns
     *  its (non-negative) ID in FabMap (different to the keyframe ID).
     *  Returns -1 if the frame cannot be added due to an error. */
//  int add(KeyFrame* keyframe);

    /** Checks if the keyframe is determined to be the same as an already
     *  added frame and if yes, returns its ID. If not, returns -1.
     *  Does not directly return a KeyFrame pointer to allow for KeyFrames
     *  being deleted. */
//  int compare(KeyFrame* keyframe);

    /** Combination of compare() followed by add() (more efficient). */
    void compareAndAdd(Frame* keyframe, int* out_newID, int* out_loopID);

    /** Returns if the class is initialized correctly (i.e. if the required
     *  files could be loaded). */
    bool isValid() const;

    int nextImageID;
    cv::Ptr<cv::FeatureDetector> detector;
    cv::Ptr<cv::BOWImgDescriptorExtractor> bide;
    cv::Ptr<of2::FabMap> fabMap;

    bool printConfusionMatrix;
    cv::Mat confusionMat;

    bool valid;


In line 8, above code tries to re-define the namespace cv with the two class that supposedly belong to feature2D module ? I am having difficulty understanding this code as I have not worked much with C++. I am ok with C though.

Kindly help me in resolving the error and compiling the package !

edit retag flag offensive close merge delete



In line 8, above code tries to re-define the namespace cv

no, that's only a (forward) declaration., not a definition. still, bad enough, it should not be there.

also note, that the features2d api has changed significantly from opencv 2.4 to current 4.1, you probably cannot use that code "as-is".

try to remove the namespace cv part, and #include <opencv2/features2d.hpp"> instead.

berak gravatar imageberak ( 2019-06-18 01:00:28 -0600 )edit