Open zouxianghong opened 6 years ago
Hi, Have you tried Release mode, it works for me.
@zouxianghong Did you find the answer for this?
check your compiler option, i think maybe we should remove -march=native
Could it be related to https://github.com/RainerKuemmerle/g2o/issues/557 ? I get the "data is not aligned" assertion failure when -mf16c
compilation flag is used (which is included by -march=native
on my machine). Running in Release mode is just a way to ignore the assert but does not solve the underlying problem.
谢谢,收到
I encountered the same problem with g2o and eigen (and pcl).
Turns out it really is because of SSE and AVX flags. If any of those are in use, Eigen changes its behavior to align data. This includes special allocators and overwriting new/delete/malloc/free calls. Which in turn cause this assert error or even segfaults (double free) if data is not correctly handled. It happens when different parts of your application (such as the app itself and/or two libraries exchange data) and one was compiled with SSE/AVX (and thus euler) and the other was not.
This happens when the libraries and your application use different build flags. In particular:
-march=native -mavx2 -msse4.2 -fpmath=sse
=> So if you link with these libraries your application must be built with the same flags.tl;dr; Make sure all your libraries and your application are built with the same SSE/AVX flags.
谢谢,收到
1.Problem Description: when using my own edge() and vertex() to do optimization, i got an error: "((size_t(m_data) % (((int)1 >= (int)internal::traits::Alignment) ? (int)1 : (int)internal::traits::Alignment)) == 0) && \"data is not aligned\""
2.Code: 2.1.Definition of Vertex and Edge `enum BlendType { POSE_ESTIMATION_2D2D = 0, POSE_ESTIMATION_2D3D_1 = 1, POSE_ESTIMATION_2D3D_2 = 2, POSE_ESTIMATION_3D2D_1 = 3, POSE_ESTIMATION_3D2D_2 = 4, POSE_ESTIMATION_3D3D_1 = 5, POSE_ESTIMATION_3D3D_2 = 6, POSE_ESTIMATION_3D3D_3 = 7 };
/** \brief Vertex for blend: 2d-2d/2d-3d/3d-2d/3d-3d bundleadjustment(pose only)
Pose: {theta_x, theta_y, theta_z, T_1, T_2, T_3} */ class VertexBlendPoseOnly: public g2o::BaseVertex<6, Vector6d> { public:
virtual void setToOriginImpl() { _estimate.fill(0.); }
virtual void oplusImpl(const double* update) { Eigen::Map v(update);
_estimate += v;
}
virtual bool read(std::istream& in) { Vector6d lv; for (int i=0; i<6; i++) in >> _estimate[i]; return true; } virtual bool write(std::ostream& out) const { Vector6d lv=estimate(); for (int i=0; i<6; i++){ out << lv[i] << " "; } return out.good(); }
public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
// Edge for blend: 2d-2d/2d-3d/3d-2d/3d-3d bundleadjustment(pose only) class EdgeBlendPoseOnly: public g2o::BaseUnaryEdge<1, Eigen::Matrix<double,1,1>, VertexBlendPoseOnly> { public: /**/ EdgeBlendPoseOnly( const BlendType& blend_type, const Eigen::Vector3d& Pc_1, const Eigen::Vector3d& Pc_2) : blendtype(blend_type), Pc1(Pc_1), Pc2(Pc_2) { information().setIdentity(); }
void computeError() { const VertexBlendPoseOnly v = static_cast<const VertexBlendPoseOnly>(_vertices[0]); const Vector6d pose = v->estimate(); double theta_x = pose[0], theta_y = pose[1], theta_z = pose[2], T_1 = pose[3], T_2 = pose[4], T_3 = pose[5]; double theta_x_2 = theta_xtheta_x; double theta_y_2 = theta_ytheta_y; double theta_z_2 = theta_ztheta_z; double theta_x_theta_y = theta_x theta_y; double theta_x_theta_z = theta_x theta_z; double theta_y_theta_z = theta_y theta_z; double sum_square_theta = theta_x_2 + theta_y_2 + theta_z_2; double sqrt_sum_square_theta = sqrt(sum_square_theta); double part_1 = (1-cos(sqrt_sum_square_theta))/sum_square_theta; double part_2 = sin(sqrt_sum_square_theta)/sqrt_sum_square_theta;
}
//virtual void linearizeOplus();
virtual bool read(std::istream& in){} virtual bool write(std::ostream& out) const {}
BlendType getBlendType() const {return blendtype;}
private:
BlendType blendtype; //< Blend type: 2D2D/2D3D_1/2D3D_2/3D2D_1/3D2D_2/3D3D_1/3D3D_2/3D3D_3
// Note: Pc(Xc,Yc,Yz) is the (normalization) camera coordinate of P // for 2D-2D: Pc1 is (Xc_1/Zc_1,Yc_1/Zc_1,1), Pc2 is (Xc_2/Zc_2,Yc_2/Zc_2,1) // for 2D-3D: Pc1 is (Xc_1/Zc_1,Yc_1/Zc_1,1), Pc2 is (Xc_2,Yc_2,Zc_2) // for 3D-2D: Pc1 is (Xc_1,Yc_1,Zc_1), Pc2 is (Xc_2/Zc_2,Yc_2/Zc_2,1) // for 3D-3D: Pc1 is (Xc_1,Yc_1,Zc_1), Pc2 is (Xc_2,Yc_2,Zc_2) Eigen::Vector3d Pc1;
// Note: Pc(Xc,Yc,Yz) is the (normalization) camera coordinate of P // for 2D-2D: Pc1 is (Xc_1/Zc_1,Yc_1/Zc_1,1), Pc2 is (Xc_2/Zc_2,Yc_2/Zc_2,1) // for 2D-3D: Pc1 is (Xc_1/Zc_1,Yc_1/Zc_1,1), Pc2 is (Xc_2,Yc_2,Zc_2) // for 3D-2D: Pc1 is (Xc_1,Yc_1,Zc_1), Pc2 is (Xc_2/Zc_2,Yc_2/Zc_2,1) // for 3D-3D: Pc1 is (Xc_1,Yc_1,Zc_1), Pc2 is (Xc_2,Yc_2,Zc_2) Eigen::Vector3d Pc2;
public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
2.2.Do optimization
include
include
include
include <opencv2/imgcodecs/imgcodecs.hpp>
include <opencv2/highgui/highgui.hpp>
include <opencv2/imgproc/imgproc.hpp>
include "RGBD_IndoorMapping/common_include.h"
include "RGBD_IndoorMapping/config.h"
include "RGBD_IndoorMapping/util.h"
include "RGBD_IndoorMapping/feature.h"
include "RGBD_IndoorMapping/feature_adjuster.h"
include "RGBD_IndoorMapping/pose_estimation.h"
include "RGBD_IndoorMapping/frame.h"
using namespace std; using namespace cv; using namespace RGBD_IndoorMapping;
int main(int argc, char** argv) { if(argc != 6) { std::cout << "Usage: test_pose_estimation image_1 image_2 depth_1 depth_2 estimation_type(init/3d2d/2d3d/3d3d/blend)." << std::endl; return -1; }
}`
3.Run and Debug I use GDB to debug the code, and i got errors below:
`0x00007ffff291c428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
1 0x00007ffff291e02a in __GI_abort () at abort.c:89
2 0x00007ffff2914bd7 in __assert_fail_base (fmt=,
3 0x00007ffff2914c82 in __GI___assert_fail (
Derived = Eigen::Map<Eigen::Matrix<double, 1, 6, 1, 1, 6>, 32, Eigen::Stride<0, 0> >]") at assert.c:101
4 0x00007ffff7b343ec in Eigen::MapBase<Eigen::Map<Eigen::Matrix<double, 1, 6, 1, 1, 6>, 32, Eigen::Stride<0, 0> >, 0>::checkSanity (this=)
5 Eigen::MapBase<Eigen::Map<Eigen::Matrix<double, 1, 6, 1, 1, 6>, 32, Eigen::Stride<0, 0> >, 0>::MapBase (cols=6, rows=1, dataPtr=, this=)
6 Eigen::MapBase<Eigen::Map<Eigen::Matrix<double, 1, 6, 1, 1, 6>, 32, Eigen::Stride<0, 0> >, 1>::MapBase (cols=6, rows=1, dataPtr=, this=)
7 Eigen::Map<Eigen::Matrix<double, 1, 6, 1, 1, 6>, 32, Eigen::Stride<0, 0> >::Map (stride=..., cols=6, rows=1, dataPtr=, this=)
8 g2o::BaseUnaryEdge<1, double, RGBD_IndoorMapping::VertexBlendPoseOnly>::linearizeOplus (this=, jacobianWorkspace=...)
9 0x00007ffff7b187ed in g2o::BlockSolver<g2o::BlockSolver<g2o::BlockSolverTraits<-1, -1> > >::buildSystem (this=0x13321ed0) at /usr/local/include/g2o/core/block_solver.hpp:512
10 0x00007ffff1f96be9 in g2o::OptimizationAlgorithmLevenberg::solve(int, bool) () from /usr/local/lib/libg2o_core.so
11 0x00007ffff1f8e5d7 in g2o::SparseOptimizer::optimize(int, bool) () from /usr/local/lib/libg2o_core.so
12 0x00007ffff7b31740 in RGBD_IndoorMapping::poseEstimationBlendG2O (state=@0x7fffffffbeac: RGBD_IndoorMapping::OK, pts_2d2d_1=std::vector of length 0, capacity 0,
13 0x00007ffff7af5d44 in RGBD_IndoorMapping::Mapping::trackWithFrame (this=this@entry=0x632c00, F=0x15986f40)
4.Asking for help I don't know why this bug happens, though i do everything i can. Anyone can help me? Thanks!