error: ISO C++ forbids declaration of ‘d’ with no type [-fpermissive]
[Click and drag to move]
这个问题也可能是C++标准的原因,在CMakeLists.txt中加上设置成C++11的就解决了
set ( CMAKE_CXX_FLAGS “-std=c++11”)
[Click and drag to move]
znkz@znkz:~/slam/ch5/joinMap$ ./joinMap
图像转换中1
段错误 (核心已转储)
[Click and drag to move]
一、产生core文件来定位段错误 https://blog.csdn.net/youngys123/article/details/79804840
znkz@znkz:~/slam/ch5/joinMap$ ulimit -a //查看core file状态,为0表示系统关闭了dump core,发生了dump core,但是禁止core文件生成
core file size (blocks, -c) 0
[Click and drag to move]
znkz@znkz:~/slam/ch5/joinMap$ ulimit -c unlimited //开启dump core
znkz@znkz:~/slam/ch5/joinMap$ ulimit -a
core file size (blocks, -c) unlimited
[Click and drag to move]
znkz@znkz:~/slam/ch5/joinMap$ gdb joinMap core
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright © 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type “show copying”
and “show warranty” for details.
This GDB was configured as “x86_64-linux-gnu”.
Type “show configuration” for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type “help”.
Type “apropos word” to search for commands related to “word”…
Reading symbols from joinMap…(no debugging symbols found)…done.
[New LWP 4002]
[New LWP 4004]
[Thread debugging using libthread_db enabled]
Using host libthread_db library “/lib/x86_64-linux-gnu/libthread_db.so.1”.
Core was generated by `./joinMap’.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000000000443959 in main ()
(gdb) bt
#0 0x0000000000443959 in main ()
(gdb) list
1 in …/sysdeps/x86_64/crti.S
[Click and drag to move]
backtrace命令(简写为bt)用来查看当前调用堆栈。第04课:GDB常用命令详解(上)
方法二:改变栈空间大小
znkz@znkz:~/slam/ch5/joinMap$ ulimit -a
stack size (kbytes, -s) 8192
znkz@znkz:~/slam/ch5/joinMap$ ulimit -s 102400
znkz@znkz:~/slam/ch5/joinMap$ ./joinMap
图像转换中1
段错误 (核心已转储)
最后:
//depthImgs.push_back(cv::imread( (fmt%"depth"%(i + 1)%"png").str(), -1 ));
depthImgs.push_back(cv::imread( (fmt%"depth"%(i + 1)%"pgm").str(), -1 ));
znkz@znkz:~/slam/ch5/joinMap$ ./joinMap
图像转换中1
点云共有1个点
在kdevelop中启动调试,先build Section,再运行——配置启动器,选择build文件夹下的可执行文件,再Debug
#通过加入判断if (!colorImgs[i].data) {cerr << "没有图片读入"} <<endl;
排查错误
//main.cpp
#include <iostream>
#include <fstream>
using namespace std;
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <eigen3/Eigen/Geometry>
#include <boost/format.hpp>
#include <pcl-1.7/pcl/point_types.h>
#include <pcl-1.7/pcl/io/pcd_io.h>
#include <pcl-1.7/pcl/visualization/pcl_visualizer.h>
int main( int argc, char** argv)
{
vector<cv::Mat> colorImgs, depthImgs;
vector<Eigen::Isometry3d, Eigen::aligned_allocator<Eigen::Isometry3d> > 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() ));
if (!colorImgs[i].data)
{
cerr << "读取不到图片" << endl;
return 0;
}
depthImgs.push_back(cv::imread( (fmt%"depth"%(i + 1)%"pgm").str(), -1 ));
double data[7] = {0};
for (auto& d:data)
{
fin >> d;
}
Eigen::Quaterniond q( data[6], data[3], data[4], data[5]);
Eigen::Isometry3d T(q);
T.pretranslate(Eigen::Vector3d( data[0], data[1], data[2]));
poses.push_back(T);
}
double cx = 325.5;
double cy = 253.5;
double fx = 518.0;
double fy = 519.0;
double depthScale = 1000.0;
typedef pcl::PointXYZRGB PointT;
typedef pcl::PointCloud<PointT> PointCloud;
PointCloud::Ptr pointCloud (new PointCloud);
for (int i = 0; i < 5; i++)
{
cout <<"图像转换中" << i + 1 << endl;
cv::Mat color = colorImgs[i];
cv::Mat depth = depthImgs[i];
Eigen::Isometry3d 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;
PointT p;
p.x = pointWorld[0];
p.y = pointWorld[1];
p.z = pointWorld[2];
p.b = color.data[v*color.step + u*color.channels()];
p.g = color.data[v*color.step + u*color.channels() + 1];
p.r = color.data[v*color.step + u*color.channels() + 2];
pointCloud->points.push_back( p );
}
}
pointCloud->is_dense = false;
cout << "点云共有" << pointCloud->size() << "个点" << endl;
pcl::io::savePCDFileBinary("map.pcd" , *pointCloud);
return 0;
}
//CMake-Lists.txt
set ( CMAKE_CXX_FLAGS "-std=c++11")
project(joinmap1)
#opencv
find_package(OpenCV REQUIRED)
include_directories( ${Opencv_INCLUDE_DIRS} )
#EIGEN
include_directories(" /usr/include/eigen3/")
#pcl
find_package(PCL REQUIRED COMPONENT common io)
include_directories( ${PCL_INCLUDE_DIRS} )
add_definitions( ${PCL_DEFINITIONS} )
add_executable(joinmap1 main.cpp)
target_link_libraries( joinmap1 ${OpenCV_LIBS} ${PCL_LIBRARIES} )