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

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

  

  一、设置环境变量

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

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

    D:opencvuildx86vc12in;D:ffmpeg-r16537-gpl-lshared-win32in;D:MRPTuildVS2013inDebug;D:wxWidgets-3.1.0libvc_dll;D:zlib-1.2.8win32Debug;

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

    D:MRPTuildVS2013inRelease;D:zlib-1.2.8win32Release;

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

  

  二、VS2013项目设置

  1、先将D:Program Filesmrpt-1.4.0includemrptmrpt-configmrpt目录下的config.h和version.h复制到D:Program Filesmrpt-1.4.0includemrpt目录下。

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

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

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

    添加目录D:Program Filesmrpt-1.4.0include 和 D:Program Filesmrpt-1.4.0libsXXXXinclude

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

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

    

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

    在配置Debug中添加目录  D:MRPTuildVS2013libDebug

    在配置Release中添加目录  D:MRPTuildVS2013libRelease

  三、编写代码

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

 1 // mrptTest.cpp : 定义控制台应用程序的入口点。
 2 //
 3 
 4 #include "stdafx.h"
 5 #include <mrpt/poses/CPoint3D.h>
 6 #include <mrpt/poses/CPose2D.h>
 7 #include <mrpt/poses/CPose3D.h>
 8 #include <mrpt/utils/CTicTac.h>
 9 
10 using namespace mrpt::utils;
11 using namespace mrpt::poses;
12 using namespace std;
13 
14 
15 int _tmain(int argc, _TCHAR* argv[])
16 {
17     try
18     {
19         // The landmark (global) position: 3D (x,y,z)
20         CPoint3D L(0, 4, 2);
21 
22         // Robot pose: 2D (x,y,phi)
23         CPose2D  R(2, 1, DEG2RAD(45.0f));
24 
25         // Camera pose relative to the robot: 6D (x,y,z,yaw,pitch,roll).
26         CPose3D  C(0.5f, 0.5f, 1.5f, DEG2RAD(-90.0f), DEG2RAD(0), DEG2RAD(-90.0f));
27 
28         // TEST 1. Relative position L' of the landmark wrt the camera
29         // --------------------------------------------------------------
30         cout << "L: " << L << endl;
31         cout << "R: " << R << endl;
32         cout << "C: " << C << endl;
33         cout << "R+C:" << (R + C) << endl;
34         //cout << (R+C).getHomogeneousMatrix();
35 
36         CPoint3D L2;
37         CTicTac tictac;
38         tictac.Tic();
39         size_t i, N = 10000;
40         for (i = 0; i<N; i++)
41             L2 = L - (R + C);
42         cout << "Computation in: " << 1e6 * tictac.Tac() / ((double)N) << " us" << endl;
43 
44         cout << "L': " << L2 << endl;
45 
46         // TEST 2. Reconstruct the landmark position:
47         // --------------------------------------------------------------
48         CPoint3D L3 = R + C + L2;
49         cout << "R(+)C(+)L' = " << L3 << endl;
50         cout << "Should be equal to L = " << L << endl;
51 
52         // TEST 3. Distance from the camera to the landmark
53         // --------------------------------------------------------------
54         cout << "|(R(+)C)-L|= " << (R + C).distanceTo(L) << endl;
55         cout << "|L-(R(+)C)|= " << (R + C).distanceTo(L) << endl;
56 
57         return 0;
58     }
59     catch (exception &e)
60     {
61         cerr << "EXCEPCTION: " << e.what() << endl;
62         return -1;
63     }
64     catch (...)
65     {
66         cerr << "Untyped excepcion!!";
67         return -1;
68     }
69 }

  运行后的结果如下:

  

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

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

原文地址:https://www.cnblogs.com/xuanxiaochen/p/6015676.html