-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I got an error about Eigen3("data is not aligned") when using my own edge and vertex to do optimization #250
Comments
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 #557 ? I get the "data is not aligned" assertion failure when |
谢谢,收到
|
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 happens when the libraries and your application use different build flags.
tl;dr; Make sure all your libraries and your application are built with the same SSE/AVX flags. |
谢谢,收到
|
I use pcl-1.8 to solve this problem. |
谢谢,收到
|
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)
*/
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)
: blend_type_(blend_type),
Pc_1_(Pc_1),
Pc_2_(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_z*theta_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 blend_type_;}
private:
BlendType blend_type_; //< 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: Pc_1_ is (Xc_1/Zc_1,Yc_1/Zc_1,1), Pc_2_ is (Xc_2/Zc_2,Yc_2/Zc_2,1)
// for 2D-3D: Pc_1_ is (Xc_1/Zc_1,Yc_1/Zc_1,1), Pc_2_ is (Xc_2,Yc_2,Zc_2)
// for 3D-2D: Pc_1_ is (Xc_1,Yc_1,Zc_1), Pc_2_ is (Xc_2/Zc_2,Yc_2/Zc_2,1)
// for 3D-3D: Pc_1_ is (Xc_1,Yc_1,Zc_1), Pc_2_ is (Xc_2,Yc_2,Zc_2)
Eigen::Vector3d Pc_1_;
// Note: Pc(Xc,Yc,Yz) is the (normalization) camera coordinate of P
// for 2D-2D: Pc_1_ is (Xc_1/Zc_1,Yc_1/Zc_1,1), Pc_2_ is (Xc_2/Zc_2,Yc_2/Zc_2,1)
// for 2D-3D: Pc_1_ is (Xc_1/Zc_1,Yc_1/Zc_1,1), Pc_2_ is (Xc_2,Yc_2,Zc_2)
// for 3D-2D: Pc_1_ is (Xc_1,Yc_1,Zc_1), Pc_2_ is (Xc_2/Zc_2,Yc_2/Zc_2,1)
// for 3D-3D: Pc_1_ is (Xc_1,Yc_1,Zc_1), Pc_2_ is (Xc_2,Yc_2,Zc_2)
Eigen::Vector3d Pc_2_;
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=<optimized out>, assertion=assertion@entry=0x7ffff7b93ce0 "((size_t(m_data) % (((int)1 >= (int)internal::traits<Derived>::Alignment) ? (int)1 : (int)internal::traits<Derived>::Alignment)) == 0) && \"data is not aligned\"", file=file@entry=0x7ffff7b84a38 "/usr/include/eigen3/Eigen/src/Core/MapBase.h", line=line@entry=168, function=function@entry=0x7ffff7b97420 <Eigen::MapBase<Eigen::Map<Eigen::Matrix<double, 1, 6, 1, 1, 6>, 32, Eigen::Stride<0, 0> >, 0>::checkSanity() const::__PRETTY_FUNCTION__> "void Eigen::MapBase<Derived, 0>::checkSanity() const [with Derived = Eigen::Map<Eigen::Matrix<double, 1, 6, 1, 1, 6>, 32, Eigen::Stride<0, 0> >]") at assert.c:92 #3 0x00007ffff2914c82 in __GI___assert_fail ( assertion=assertion@entry=0x7ffff7b93ce0 "((size_t(m_data) % (((int)1 >= (int)internal::traits<Derived>::Alignment) ? (int)1 : (int)internal::traits<Derived>::Alignment)) == 0) && \"data is not aligned\"", file=file@entry=0x7ffff7b84a38 "/usr/include/eigen3/Eigen/src/Core/MapBase.h", line=line@entry=168, function=function@entry=0x7ffff7b97420 <Eigen::MapBase<Eigen::Map<Eigen::Matrix<double, 1, 6, 1, 1, 6>, 32, Eigen::Stride<0, 0> >, 0>::checkSanity() const::__PRETTY_FUNCTION__---Type <return> to continue, or q <return> to quit---info f 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=<optimized out>) at /usr/include/eigen3/Eigen/src/Core/MapBase.h:168 #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=<optimized out>, this=<optimized out>) at /usr/include/eigen3/Eigen/src/Core/MapBase.h:155 #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=<optimized out>, this=<optimized out>) at /usr/include/eigen3/Eigen/src/Core/MapBase.h:243 #7 Eigen::Map<Eigen::Matrix<double, 1, 6, 1, 1, 6>, 32, Eigen::Stride<0, 0> >::Map (stride=..., cols=6, rows=1, dataPtr=<optimized out>, this=<optimized out>) at /usr/include/eigen3/Eigen/src/Core/Map.h:151 #8 g2o::BaseUnaryEdge<1, double, RGBD_IndoorMapping::VertexBlendPoseOnly>::linearizeOplus (this=<optimized out>, jacobianWorkspace=...) at /usr/local/include/g2o/core/base_unary_edge.hpp:86 #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, pts_2d2d_2=std::vector of length 0, capacity 0, pts_2d3d_1=std::vector of length 4, capacity 4 = {...}, pts_2d3d_2=std::vector of length 4, capacity 4 = {...}, pts_3d2d_1=std::vector of length 1, capacity 1 = {...}, pts_3d2d_2=std::vector of length 1, capacity 1 = {...}, pts_3d3d_1=std::vector of length 267, capacity 512 = {...}, pts_3d3d_2=std::vector of length 267, capacity 512 = {...}, inliers_2d2d_index=std::vector of length 0, capacity 0, inliers_2d3d_index=std::vector of length 4, capacity 4 = {...}, inliers_3d2d_index=std::vector of length 1, capacity 1 = {...}, inliers_3d3d_index=std::vector of length 267, capacity 512 = {...}, camera=0x9f2590, distCoeffs=..., initi_T21=...) at RGBD_IndoorMapping/src/PoseEstimation.cpp:395 #13 0x00007ffff7af5d44 in RGBD_IndoorMapping::Mapping::trackWithFrame (this=this@entry=0x632c00, F=0x15986f40) at RGBD_IndoorMapping/src/Mapping.cpp:262
4.Asking for help
I don't know why this bug happens, though i do everything i can. Anyone can help me? Thanks!
The text was updated successfully, but these errors were encountered: