SLAM十四讲中的第五讲点云拼接错误解决
出现错误
CMakeFiles/joinMap.dir/joinMap.cpp.o:在函数‘showPointCloud(std::vector<Eigen::Matrix<double, 6, 1, 0, 6, 1>, Eigen::aligned_allocator<Eigen::Matrix<double, 6, 1, 0, 6, 1> > > const&)’中: joinMap.cpp:(.text+0xcd):对‘pangolin::CreateWindowAndBind(std::__cxx11::basic_string<char, std::char_traits, std::allocator >, int, int, pangolin::Params const&)’未定义的引用 joinMap.cpp:(.text+0x1a8):对‘pangolin::ModelViewLookAt(double, double, double, double, double, double, double, double, double)’未定义的引用 joinMap.cpp:(.text+0x1e8):对‘pangolin::ProjectionMatrix(int, int, double, double, double, double, double, double)’未定义的引用 joinMap.cpp:(.text+0x1f6):对‘pangolin::OpenGlRenderState::OpenGlRenderState(pangolin::OpenGlMatrix const&, pangolin::OpenGlMatrix const&)’未定义的引用 joinMap.cpp:(.text+0x1fb):对‘pangolin::CreateDisplay()’未定义的引用 joinMap.cpp:(.text+0x252):对‘pangolin::View::SetBounds(pangolin::Attach, pangolin::Attach, pangolin::Attach, pangolin::Attach, double)’未定义的引用 joinMap.cpp:(.text+0x27f):对‘pangolin::Handler3D::Handler3D(pangolin::OpenGlRenderState&, pangolin::AxisDirection, float, float)’未定义的引用 joinMap.cpp:(.text+0x28a):对‘pangolin::View::SetHandler(pangolin::Handler*)’未定义的引用 joinMap.cpp:(.text+0x299):对‘pangolin::ShouldQuit()’未定义的引用 joinMap.cpp:(.text+0x2b6):对‘pangolin::View::Activate(pangolin::OpenGlRenderState const&) const’未定义的引用 joinMap.cpp:(.text+0x346):对‘pangolin::FinishFrame()’未定义的引用 CMakeFiles/joinMap.dir/joinMap.cpp.o:在函数‘pangolin::GlTexture::~GlTexture()’中: joinMap.cpp:(.text._ZN8pangolin9GlTextureD2Ev[_ZN8pangolin9GlTextureD5Ev]+0x25):对‘pangolin::ShouldQuit()’未定义的引用 CMakeFiles/joinMap.dir/joinMap.cpp.o:在函数‘pangolin::GlTexture::Reinitialise(int, int, int, bool, int, unsigned int, unsigned int, void*)’中: joinMap.cpp:(.text._ZN8pangolin9GlTexture12ReinitialiseEiiibijjPv[_ZN8pangolin9GlTexture12ReinitialiseEiiibijjPv]+0x12b):对‘pangolin::glErrorString(unsigned int)’未定义的引用 CMakeFiles/joinMap.dir/joinMap.cpp.o:在函数‘pangolin::GlTexture::~GlTexture()’中: joinMap.cpp:(.text._ZN8pangolin9GlTextureD0Ev[_ZN8pangolin9GlTextureD5Ev]+0x29):对‘pangolin::ShouldQuit()’未定义的引用 CMakeFiles/joinMap.dir/joinMap.cpp.o:在函数‘void std::vector<Sophus::SE3, Eigen::aligned_allocatorSophus::SE3 >::_M_realloc_insert<Sophus::SE3 const&>(__gnu_cxx::__normal_iterator<Sophus::SE3*, std::vector<Sophus::SE3, Eigen::aligned_allocatorSophus::SE3 > >, Sophus::SE3 const&)’中: joinMap.cpp:(.text.ZNSt6vectorIN6Sophus3SE3EN5Eigen17aligned_allocatorIS1_EEE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S5_EEDpOT[ZNSt6vectorIN6Sophus3SE3EN5Eigen17aligned_allocatorIS1_EEE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S5_EEDpOT]+0x78):对‘Sophus::SE3::SE3(Sophus::SE3 const&)’未定义的引用 joinMap.cpp:(.text.ZNSt6vectorIN6Sophus3SE3EN5Eigen17aligned_allocatorIS1_EEE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S5_EEDpOT[ZNSt6vectorIN6Sophus3SE3EN5Eigen17aligned_allocatorIS1_EEE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S5_EEDpOT]+0x9c):对‘Sophus::SE3::SE3(Sophus::SE3 const&)’未定义的引用 joinMap.cpp:(.text.ZNSt6vectorIN6Sophus3SE3EN5Eigen17aligned_allocatorIS1_EEE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S5_EEDpOT[ZNSt6vectorIN6Sophus3SE3EN5Eigen17aligned_allocatorIS1_EEE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S5_EEDpOT]+0xcc):对‘Sophus::SE3::SE3(Sophus::SE3 const&)’未定义的引用 CMakeFiles/joinMap.dir/joinMap.cpp.o:在函数‘main’中: joinMap.cpp:(.text.startup+0x56f):对‘Sophus::SE3::SE3(Eigen::Quaternion<double, 0> const&, Eigen::Matrix<double, 3, 1, 0, 3, 1> const&)’未定义的引用 joinMap.cpp:(.text.startup+0x592):对‘Sophus::SE3::SE3(Sophus::SE3 const&)’未定义的引用 joinMap.cpp:(.text.startup+0x859):对‘Sophus::SE3::SE3(Sophus::SE3 const&)’未定义的引用 joinMap.cpp:(.text.startup+0x926):对‘Sophus::SE3::operator*(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&) const’未定义的引用 CMakeFiles/joinMap.dir/joinMap.cpp.o:(.data.rel+0x0):对‘vtable for pangolin::HandlerScroll’未定义的引用 CMakeFiles/joinMap.dir/joinMap.cpp.o:(.data.rel+0x8):对‘vtable for pangolin::Handler’未定义的引用 collect2: error: ld returned 1 exit status CMakeFiles/joinMap.dir/build.make:343: recipe for target ‘joinMap’ failed make[2]: *** [joinMap] Error 1 CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/joinMap.dir/all’ failed make[1]: *** [CMakeFiles/joinMap.dir/all] Error 2 Makefile:129: recipe for target ‘all’ failed make: *** [all] Error 2
CMakeliste.txt文件,改成下面的样子
cmake_minimum_required(VERSION 2.8)
project(joinMap)
set( CMAKE_BUILD_TYPE Release )
set( CMAKE_CXX_FLAGS "-std=c++11 -O3")
# 包含opencv库
find_package( OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS})
#包含eigen库
find_package( Eigen3 REQUIRED)
include_directories( "/usr/include/eigen3/" )
#pangolin
find_package(Pangolin)
include_directories( ${Pangolin_INCLUDE_DIRS} )
#Sophus
find_package(Sophus)
include_directories( "/usr/include/sophus/" )
#包含pcl库
find_package( PCL REQUIRED common io)
include_directories( ${PCL_INCLUDE_DIRS})
add_definitions( ${PCL_DEFINITIONS})
list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
LINK_LIBRARIES(${PCL_LIBRARY_DIRS})
add_executable(joinMap joinMap.cpp)
target_link_libraries(joinMap ${OpenCV_LIBS} ${PCL_LIBRARIES} ${Pangolin_LIBRARIES} ${Sophus_LIBRARIES})
install(TARGETS joinMap RUNTIME DESTINATION bin)
出现错误
fatal error: sophus/se3.hpp: 没有那个文件或目录 #include <sophus/se3.hpp> ^~~~~~~~~~~~~~~~ compilation terminated.
这种类似的问题的时候,先看你电脑里面这个声明的头文件是.h文件还是.hpp文件,然后 将joinmap.cpp文件的头文件声明改称电脑中该文件的样子。 我的就改成了下面这个样子
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include <boost/format.hpp>
#include <pangolin/pangolin.h>
#include <sophus/se3.h>
joinMap.cpp
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include <boost/format.hpp>
#include <pangolin/pangolin.h>
#include <sophus/se3.h>
using namespace std;
typedef vector<Sophus::SE3, Eigen::aligned_allocator<Sophus::SE3>> TrajectoryType;
typedef Eigen::Matrix<double, 6, 1> Vector6d;
void showPointCloud(
const vector<Vector6d, Eigen::aligned_allocator<Vector6d>> &pointcloud);
int main(int argc, char **argv) {
vector<cv::Mat> colorImgs, depthImgs;
TrajectoryType poses;
ifstream fin("./pose.txt");
if (!fin) {
cerr << "请在有pose.txt的目录下运行此程序" << endl;
return 1;
}
for (int i = 0; i < 5; i++) {
boost::format fmt("./%s/%d.%s");
colorImgs.push_back(cv::imread((fmt % "color" % (i + 1) % "png").str()));
depthImgs.push_back(cv::imread((fmt % "depth" % (i + 1) % "pgm").str(), -1));
double data[7] = {0};
for (auto &d:data)
fin >> d;
Sophus::SE3 pose(Eigen::Quaterniond(data[6], data[3], data[4], data[5]),
Eigen::Vector3d(data[0], data[1], data[2]));
poses.push_back(pose);
}
double cx = 325.5;
double cy = 253.5;
double fx = 518.0;
double fy = 519.0;
double depthScale = 1000.0;
vector<Vector6d, Eigen::aligned_allocator<Vector6d>> pointcloud;
pointcloud.reserve(1000000);
for (int i = 0; i < 5; i++) {
cout << "转换图像中: " << i + 1 << endl;
cv::Mat color = colorImgs[i];
cv::Mat depth = depthImgs[i];
Sophus::SE3 T = poses[i];
for (int v = 0; v < color.rows; v++)
for (int u = 0; u < color.cols; u++) {
unsigned int d = depth.ptr<unsigned short>(v)[u];
if (d == 0) continue;
Eigen::Vector3d point;
point[2] = double(d) / depthScale;
point[0] = (u - cx) * point[2] / fx;
point[1] = (v - cy) * point[2] / fy;
Eigen::Vector3d pointWorld = T * point;
Vector6d p;
p.head<3>() = pointWorld;
p[5] = color.data[v * color.step + u * color.channels()];
p[4] = color.data[v * color.step + u * color.channels() + 1];
p[3] = color.data[v * color.step + u * color.channels() + 2];
pointcloud.push_back(p);
}
}
cout << "点云共有" << pointcloud.size() << "个点." << endl;
showPointCloud(pointcloud);
return 0;
}
void showPointCloud(const vector<Vector6d, Eigen::aligned_allocator<Vector6d>> &pointcloud) {
if (pointcloud.empty()) {
cerr << "Point cloud is empty!" << endl;
return;
}
pangolin::CreateWindowAndBind("Point Cloud Viewer", 1024, 768);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(1024, 768, 500, 500, 512, 389, 0.1, 1000),
pangolin::ModelViewLookAt(0, -0.1, -1.8, 0, 0, 0, 0.0, -1.0, 0.0)
);
pangolin::View &d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, pangolin::Attach::Pix(175), 1.0, -1024.0f / 768.0f)
.SetHandler(new pangolin::Handler3D(s_cam));
while (pangolin::ShouldQuit() == false) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
d_cam.Activate(s_cam);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glPointSize(2);
glBegin(GL_POINTS);
for (auto &p: pointcloud) {
glColor3d(p[3] / 255.0, p[4] / 255.0, p[5] / 255.0);
glVertex3d(p[0], p[1], p[2]);
}
glEnd();
pangolin::FinishFrame();
usleep(5000);
}
return;
}
|