MRPT笔记——使用编译好的MRPT库建立VS2013项目

时间:2023-03-08 23:39:42
MRPT笔记——使用编译好的MRPT库建立VS2013项目

  接着上一篇《MRPT在VS2013中的配置》,下面接收如何使用编译好的MRPT建立工程项目。

  

  一、设置环境变量

  上一篇中,配置MRPT时,使用到了几个相关库,opencv、zlib、wxWidgets、ffmpeg。

  设置环境变量,添加路径PATH:

    D:\opencv\build\x86\vc12\bin;D:\ffmpeg-r16537-gpl-lshared-win32\bin;D:\MRPT\buildVS2013\bin\Debug;D:\wxWidgets-3.1.0\lib\vc_dll;D:\zlib-1.2.8\win32\Debug;

  如果需要编译Release版本,则需另外添加:

    D:\MRPT\buildVS2013\bin\Release;D:\zlib-1.2.8\win32\Release;

  添加这些路径,主要是把项目可能用到的DLL文件加载到PATH路径中。

  

  二、VS2013项目设置

  1、先将D:\Program Files\mrpt-1.4.0\include\mrpt\mrpt-config\mrpt目录下的config.h和version.h复制到D:\Program Files\mrpt-1.4.0\include\mrpt目录下。

  2、打开VS2013,建立mrptTest项目:

    新建项目——C++——设置文件名mrptTest——WIN32控制台应用程序

  3、打开工程属性——VC++目录——包含目录 :

    添加目录D:\Program Files\mrpt-1.4.0\include 和 D:\Program Files\mrpt-1.4.0\libs\XXXX\include

    第二个包含选项众多,我是将所有libs目录下所有的mrpt文件夹复制到D:\MRPT\buildVS2013\include,然后再添加该目录。

    需要用wxWidgets,则添加D:\wxWidgets-3.1.0\include

    

  4、打开工程属性——VC++ 目录——库目录:

    在配置Debug中添加目录  D:\MRPT\buildVS2013\lib\Debug

    在配置Release中添加目录  D:\MRPT\buildVS2013\lib\Release

  三、编写代码

  这里采用MRPT的例子,参考 https://raw.githubusercontent.com/MRPT/mrpt/master/doc/mrpt_example1/test.cpp

 // mrptTest.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <mrpt/poses/CPoint3D.h>
#include <mrpt/poses/CPose2D.h>
#include <mrpt/poses/CPose3D.h>
#include <mrpt/utils/CTicTac.h> using namespace mrpt::utils;
using namespace mrpt::poses;
using namespace std; int _tmain(int argc, _TCHAR* argv[])
{
try
{
// The landmark (global) position: 3D (x,y,z)
CPoint3D L(, , ); // Robot pose: 2D (x,y,phi)
CPose2D R(, , DEG2RAD(45.0f)); // Camera pose relative to the robot: 6D (x,y,z,yaw,pitch,roll).
CPose3D C(0.5f, 0.5f, 1.5f, DEG2RAD(-90.0f), DEG2RAD(), DEG2RAD(-90.0f)); // TEST 1. Relative position L' of the landmark wrt the camera
// --------------------------------------------------------------
cout << "L: " << L << endl;
cout << "R: " << R << endl;
cout << "C: " << C << endl;
cout << "R+C:" << (R + C) << endl;
//cout << (R+C).getHomogeneousMatrix(); CPoint3D L2;
CTicTac tictac;
tictac.Tic();
size_t i, N = ;
for (i = ; i<N; i++)
L2 = L - (R + C);
cout << "Computation in: " << 1e6 * tictac.Tac() / ((double)N) << " us" << endl; cout << "L': " << L2 << endl; // TEST 2. Reconstruct the landmark position:
// --------------------------------------------------------------
CPoint3D L3 = R + C + L2;
cout << "R(+)C(+)L' = " << L3 << endl;
cout << "Should be equal to L = " << L << endl; // TEST 3. Distance from the camera to the landmark
// --------------------------------------------------------------
cout << "|(R(+)C)-L|= " << (R + C).distanceTo(L) << endl;
cout << "|L-(R(+)C)|= " << (R + C).distanceTo(L) << endl; return ;
}
catch (exception &e)
{
cerr << "EXCEPCTION: " << e.what() << endl;
return -;
}
catch (...)
{
cerr << "Untyped excepcion!!";
return -;
}
}

  运行后的结果如下:

  MRPT笔记——使用编译好的MRPT库建立VS2013项目

  至此,官网例子测试通过,才算开始MRPT项目路程了。

  (欢迎转载,转载请注明出处。)