Re: Cplusplus Loop Closure Detection

Posted by alexfr on
URL: http://official-rtab-map-forum.206.s1.nabble.com/Cplusplus-Loop-Closure-Detection-tp686p690.html

Hi,
Thank you for your help now it works.

Tell me if I am wrong but if I understand well, this code keep comparing the image between the sample file and the database (./ros/rtabmap.db) by default until there is no more image available in the samples file. The samples file is use to simulate a camera with the function CameraImage, isn't it ?
I am trying to make my own code. I want to create a node that will take the current image from the kinect (with the function takeImage()) and use getloopclosureID with a data base I made before to get the current pose of the robot.

I just start by initiate my camera and the database path but I get the same error each time I try to catkin it.
here the code :

#include "rtabmap/core/CameraThread.h"
#include "rtabmap/core/CameraRGBD.h"
#include "rtabmap/core/CameraEvent.h"
#include "rtabmap/core/Rtabmap.h"
#include "rtabmap/core/CameraRGBD.h"
#include "rtabmap/core/Camera.h"
#include <opencv2/core/core.hpp>
#include "rtabmap/utilite/UFile.h"
#include <stdio.h>

#include "std_msgs/String.h"
#include <iostream>
#include <sstream>

#include "ros/ros.h"

using namespace rtabmap;

int main(int argc, char * argv[])
{
  ros::init(argc, argv, "getIDLoopClosure");

  int driver = 0;

  driver=1;

  rtabmap::CameraRGBD * camera = 0;

        rtabmap::Transform opticalRotation(0,0,1,0, -1,0,0,0, 0,-1,0,0);

        camera = new rtabmap::CameraOpenNI2("", 0, opticalRotation);

        rtabmap::CameraThread cameraThread(camera);

        if(!cameraThread.init())
        {
                UERROR("Camera init failed!");
                exit(1);
        }

  bool localizationMode = true;
  std::string databasePath = "/home/mugiro/Documents/RTAB-Map/test2.db";

  // Create RTAB-Map
        rtabmap::Rtabmap rtabmap;

        rtabmap.setTimeThreshold(700.0f); // Time threshold : 700 ms, 0 ms means no limit

        rtabmap::ParametersMap parameters;
        parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kRtabmapLoopThr(), "0.11"));
        parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kRGBDEnabled(), "false"));
  parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kMemIncrementalMemory(), "false"));
        parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kKpIncrementalDictionary(), "false"));
        parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kMemSTMSize(), "1"));

  rtabmap.init(parameters, databasePath);

  printf("\nDatabase directory \"%s\"\n", databasePath.c_str());

        int countLoopDetected=0;
        int i=0;

  int nextIndex = rtabmap.getLastLocationId()+1;

  printf("\nProcessing images... from directory \"%d\"\n", nextIndex);

  return 0;

}

------------------------------------------------------------------------
and here the error:

CMakeFiles/getIDLoopClosure.dir/src/loop_closure_detection.cpp.o: In function `main':
loop_closure_detection.cpp:(.text+0x17d): undefined reference to `rtabmap::Transform::Transform(float, float, float, float, float, float, float, float, float, float, float, float)'
loop_closure_detection.cpp:(.text+0x1d9): undefined reference to `rtabmap::CameraOpenNI2::CameraOpenNI2(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, float, rtabmap::Transform const&)'
loop_closure_detection.cpp:(.text+0x21c): undefined reference to `rtabmap::CameraThread::CameraThread(rtabmap::CameraRGBD*)'
loop_closure_detection.cpp:(.text+0x22c): undefined reference to `rtabmap::CameraThread::init()'
loop_closure_detection.cpp:(.text+0x257): undefined reference to `ULogger::write(ULogger::Level, char const*, int, char const*, char const*, ...)'
loop_closure_detection.cpp:(.text+0x2b3): undefined reference to `rtabmap::Rtabmap::Rtabmap()'
loop_closure_detection.cpp:(.text+0x2c8): undefined reference to `rtabmap::Rtabmap::setTimeThreshold(float)'
loop_closure_detection.cpp:(.text+0x83e): undefined reference to `rtabmap::Rtabmap::init(std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
loop_closure_detection.cpp:(.text+0x883): undefined reference to `rtabmap::Rtabmap::getLastLocationId() const'
loop_closure_detection.cpp:(.text+0x8c7): undefined reference to `rtabmap::Rtabmap::~Rtabmap()'
loop_closure_detection.cpp:(.text+0x8e7): undefined reference to `rtabmap::CameraThread::~CameraThread()'
loop_closure_detection.cpp:(.text+0xbd8): undefined reference to `rtabmap::Rtabmap::~Rtabmap()'
loop_closure_detection.cpp:(.text+0xc02): undefined reference to `rtabmap::CameraThread::~CameraThread()'
CMakeFiles/getIDLoopClosure.dir/src/loop_closure_detection.cpp.o: In function `xn::NodeWrapper::SetHandle(XnInternalNodeData*)':
loop_closure_detection.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[xn::NodeWrapper::SetHandle(XnInternalNodeData*)]+0x38): undefined reference to `xnGetRefContextFromNodeHandle'
loop_closure_detection.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[xn::NodeWrapper::SetHandle(XnInternalNodeData*)]+0x53): undefined reference to `xnContextUnregisterFromShutdown'
loop_closure_detection.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[xn::NodeWrapper::SetHandle(XnInternalNodeData*)]+0x5f): undefined reference to `xnContextRelease'
loop_closure_detection.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[xn::NodeWrapper::SetHandle(XnInternalNodeData*)]+0x6e): undefined reference to `xnProductionNodeRelease'
loop_closure_detection.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[xn::NodeWrapper::SetHandle(XnInternalNodeData*)]+0x81): undefined reference to `xnProductionNodeAddRef'
loop_closure_detection.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[xn::NodeWrapper::SetHandle(XnInternalNodeData*)]+0x90): undefined reference to `xnGetRefContextFromNodeHandle'
loop_closure_detection.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[xn::NodeWrapper::SetHandle(XnInternalNodeData*)]+0xb1): undefined reference to `xnContextRegisterForShutdown'
loop_closure_detection.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[xn::NodeWrapper::SetHandle(XnInternalNodeData*)]+0xc0): undefined reference to `xnContextRelease'
collect2: ld returned 1 exit status
make[2]: *** [/home/mugiro/alex_package/devel/lib/check_point/getIDLoopClosure] Error 1
make[1]: *** [check_point/CMakeFiles/getIDLoopClosure.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed




I installed rtabmap using sudo apt-get install. How can I solve the problem?

Thanks so much for your help.