捣鼓了两天了,经历了cmake的无数摧残,无数次配置系统的环境变量,先后安装了QT5,PCL库,wxWidgets以及各种不知名的其他玩意VS在最后编译时还是会各种毛病...已处于崩溃边缘。
(希望你们不要跟我一样走这条路,相信我真的不好走...自己编译是真的有太太太多坑了,特别是这个mrpt,不会像opencv那样容易)
最后还是自己摸索出,直接用安装好的那个mrpt目录(注意,这里的安装目录就是在官网上,下载那个windows版本的安装包,就像装软件一样,在安装过程中不是有个add path in 系统变量,会失败,找了好久解决方案,没找到所以放弃。就是因为这个系统变量也没添加进去,导致后面在VS中瞎配半天也成功不了,我也是服。ps:安装PCL点云包时也是一样的,吐槽:微软非要把这个path的容量设置那么小,再吐槽:mrpt官方那个维护有没有考虑过windows用户的感受,哭T T)在vs2019中配置,看图。
这是新建的一个项目,直接在右边这里的属性页面添加无数多个依赖的目录, 添加的路径都长这样,
没错,一个个手动的添加到VS的这个包含目录下,比如我的全部在包含目录下的路径:
D:\Program Files\opencv\build\include\opencv2
D:\vtk\LIb\include\vtk-8.2
D:\ITK\ITK\include\ITK-4.13
D:\mrpt\include\mrpt\apps\include
D:\mrpt\include\mrpt\bayes\include
D:\mrpt\include\mrpt\system\include
D:\mrpt\include\mrpt\slam\include
D:\mrpt\include\mrpt\serialization\include
D:\mrpt\include\mrpt\rtti\include
D:\mrpt\include\mrpt\random\include
D:\mrpt\include\mrpt\opengl\include
D:\mrpt\include\mrpt\obs\include
D:\mrpt\include\mrpt\nav\include
D:\mrpt\include\mrpt\nanogui\include
D:\mrpt\include\mrpt\math\include
D:\mrpt\include\mrpt\maps\include
D:\mrpt\include\mrpt\kinematics\include
D:\mrpt\include\mrpt\io\include
D:\mrpt\include\mrpt\img\include
D:\mrpt\include\mrpt\hwdrivers\include
D:\mrpt\include\mrpt\gui\include
D:\mrpt\include\mrpt\graphslam\include
D:\mrpt\include\mrpt\graphs\include
D:\mrpt\include\mrpt\expr\include
D:\mrpt\include\mrpt\detectors\include
D:\mrpt\include\mrpt\core\include
D:\mrpt\include\mrpt\containers\include
D:\mrpt\include\mrpt\config\include
D:\mrpt\include\mrpt\comms\include
D:\mrpt\include\mrpt\tclap\include
D:\mrpt\include\mrpt\vision\include
D:\mrpt\include\mrpt\typemeta\include
D:\mrpt\include\mrpt\topography\include
D:\mrpt\include\mrpt\tfest\include
当然链接器--输入那里的依赖包我就不多说了,配置过opencv,或者VTK的应该都知道。然后我现在还在解决VS中MRPT那个源码还有好多编译不了的。比如说现在这种头文件终于不报错了:
but, 看下图....
找了找网上,说要c++编译器要用17版本,改了,没用。要安装其他的组件,装了,我实在不知道是不是还需要装游戏开发的unity了(不用),太难了吧。
当我耐心的装完一些我也不知道有没有用的插件,然后会来,发现还是没起作用,后面突然把debug模式改为release,诶,我发现源码终于不再报一些乱七八糟的错误了~!老天待我不薄啊!!!记得还是要改编译器成17版本。
再配置好opencv,满欢期待,好家伙,又来错误了= =,内心是崩溃的。。
好家伙,我在链接器--输入那里把opencv 和mrpt的依赖包全部加上,如图:
好家伙好家伙,程序终于跑出来了呜呜呜,两天了。啊,我要哭了~不管是个啥总之运行成功了不是,感动中....
附上上面这个示例的官方的测试代码,我还小小的改动了一下:
// temp.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
/* +---------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| http://www.mrpt.org/ |
| |
| Copyright (c) 2005-2015, Individual contributors, see AUTHORS file |
| See: http://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See details in http://www.mrpt.org/License |
+---------------------------------------------------------------------------+ */
#include <fstream>
#include <vector>
#include <mrpt/gui/CDisplayWindowPlots.h>
#include <mrpt/math/distributions.h>
#include <mrpt/system/os.h>
//#include <mrpt/system/thread_name.h>
#include <windows.h>
//#include <mrpt/system/threads_name.h>
#include <opencv2/opencv.hpp>
#define MRPT_NO_WARN_BIG_HDR
//#include <mrpt/base.h>
using namespace cv;
using namespace mrpt;
using namespace mrpt::gui;
using namespace mrpt::math;
//using namespace mrpt::utils;
using namespace std;
void myOnMenu(int menuID, float x, float y, void* param)
{
switch (menuID)
{
case 0:
cout << "Menu0: " << menuID << endl << " x=" << x << " y=" << y << endl;
break;
case 1:
cout << "hmmmmm" << endl;
break;
default:
break;
}
}
// ------------------------------------------------------
// TestDisplayPlots
// ------------------------------------------------------
void TestDisplayPlots()
{
ifstream fileDPose;
fileDPose.open("../pose_vioEKF.txt");
CDisplayWindowPlots win("Example of function plot", 400, 400);
win.hold_on();
win.enableMousePanZoom(true);
win.addPopupMenuEntry("Menu0", 0);
win.addPopupMenuEntry("Menu1", 1);
win.setMenuCallback(myOnMenu);
//win.axis(-100,100,-100,100);
while (!fileDPose.eof())
{
double tmp[16] = { 0 }; tmp[15] = 1;
for (int j = 0; j < 12; j++)
fileDPose >> tmp[j];
std::vector<double> x, y;
x.push_back(tmp[3]);
y.push_back(tmp[7]);
win.plot(x, y, "r.3");
win.axis_fit();
win.axis_equal(true);
Sleep(10);
}
win.hold_off();
while (1) { Sleep(50); }
// Mat img = imread("/home/zero/Desktop/displayPlots/zero.jpg");
// IplImage ts = img;
// CImage zero;
// zero.setFromIplImage(&ts);
// CDisplayWindowPlots winzero("Example of function plot",400,400);
// winzero.image(zero, 0,0,400,400);
// winzero.axis_equal();
// CDisplayWindowPlots win("Example of function plot",400,300);
// win.enableMousePanZoom(true);
// win.addPopupMenuEntry("Mark this point...",1);
// win.setMenuCallback(myOnMenu);
// Generate data for a 2D plot:
// CVectorDouble X,Y;
// for (double x=0;x<5;x+=0.01f)
// {
// double y = math::normalPDF(x, 2,0.3);
// X.push_back(x);
// Y.push_back(y);
// }
// win.plot(X,Y,"r-3");
// win.axis_equal(false);
// win.axis_fit();
// win.setPos(10,10);
// win.hold_on();
// win.plot(X,"b.3");
// X = X+Y;
// win.plot(X,Y,"r.3");
// win.resize(800,600);
// win.axis_fit();
// while (1)
// {
// int x,y;
// mrpt::system::sleep(50);
// win.getLastMousePosition(x,y);
// cout << x << " " << y <<endl;
// cout.flush();
// }
}
// ------------------------------------------------------
// MAIN
// ------------------------------------------------------
int main()
{
try
{
TestDisplayPlots();
return 0;
}
catch (std::exception& e)
{
std::cout << "MRPT exception caught: " << e.what() << std::endl;
return -1;
}
catch (...)
{
printf("Untyped exception!!");
return -1;
}
}