laurentkneip / opengv

OpenGV is a collection of computer vision methods for solving geometric vision problems. It is hosted and maintained by the Mobile Perception Lab of ShanghaiTech.
Other
1.02k stars 353 forks source link

Error in relative pose estimation #46

Closed kafeiyin00 closed 7 years ago

kafeiyin00 commented 7 years ago

`//relative pose opengv::relative_pose::CentralRelativeAdapter adapter( bvReference, bvCurrent );

// create a RANSAC object
opengv::sac::Ransac<opengv::sac_problems::relative_pose::CentralRelativePoseSacProblem> ransac;
std::cout<<"2.1\n";
// create a CentralRelativePoseSacProblem
// (set algorithm to STEWENIUS, NISTER, SEVENPT, or EIGHTPT)
std::shared_ptr<opengv::sac_problems::relative_pose::CentralRelativePoseSacProblem>
        relposeproblem_ptr(
        new opengv::sac_problems::relative_pose::CentralRelativePoseSacProblem(
                adapter,
                opengv::sac_problems::relative_pose::CentralRelativePoseSacProblem::EIGHTPT ) );

ransac.sac_model_ = relposeproblem_ptr;
ransac.threshold_ = ego_ransac_threashold_inlers;
ransac.max_iterations_ = iteration_num;
ransac.computeModel();
std::cout<<"2.2\n";
inliers = ransac.inliers_;
//std::cout <<ransac.model_coefficients_<<std::endl;
Crc = ransac.model_coefficients_.block(0,0,2,2);
Rcr = ransac.model_coefficients_.block(0,3,2,3);
std::cout<<inliers.size()<<std::endl;
if(bNonlieanerOpitimize)
{
    opengv::bearingVectors_t bvReferenceNonlinear;
    opengv::bearingVectors_t bvCurrentNonlinear;
    for (int i = 0; i < inliers.size(); ++i) {
        bvReferenceNonlinear.push_back(bvReference[inliers[i]]);
        bvCurrentNonlinear.push_back(bvCurrent[inliers[i]]);
    }
    opengv::relative_pose::CentralRelativeAdapter adapterNolinear(
            bvReferenceNonlinear, bvCurrentNonlinear,Rcr,Crc);
    std::cout<<"2.3\n";
    opengv::transformation_t nonlinear_transformation =
            opengv::relative_pose::optimize_nonlinear(adapterNolinear);
    std::cout<<"2.4\n";
    Crc = nonlinear_transformation.block(0,0,2,2);
    Rcr = nonlinear_transformation.block(0,3,2,3);
}`

I use the above code to estimate relative pose of two image, sometimes error occurs in opengv::transformation_t nonlinear_transformation = opengv::relative_pose::optimize_nonlinear(adapterNolinear);

/usr/include/eigen3/Eigen/src/Core/DenseStorage.h:128:Eigen::internal::plain_array<T, Size, MatrixOrArrayOptions, 32>::plain_array() [with T = double; int Size = 12; int MatrixOrArrayOptions = 0]: 假设 ‘(reinterpret_cast(eigen_unaligned_array_assert_workaround_gcc47(array)) & (31)) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" " READ THIS WEB PAGE !!! "’ 失败。

laurentkneip commented 7 years ago

This is a veru strange error. Are you entirely sure that you are using the same Eigen versions? On 09/04/2017 2:56 PM, "lijianping" notifications@github.com wrote:

`//relative pose opengv::relative_pose::CentralRelativeAdapter adapter( bvReference, bvCurrent );

// create a RANSAC object opengv::sac::Ransac ransac; std::cout<<"2.1\n"; // create a CentralRelativePoseSacProblem // (set algorithm to STEWENIUS, NISTER, SEVENPT, or EIGHTPT) std::shared_ptr relposeproblem_ptr( new opengv::sac_problems::relative_pose::CentralRelativePoseSacProblem( adapter, opengv::sac_problems::relative_pose::CentralRelativePoseSacProblem::EIGHTPT ) );

ransac.sacmodel = relposeproblemptr; ransac.threshold = ego_ransac_threashold_inlers; ransac.maxiterations = iterationnum; ransac.computeModel(); std::cout<<"2.2\n"; inliers = ransac.inliers; //std::cout <<ransac.modelcoefficients<<std::endl; Crc = ransac.modelcoefficients.block(0,0,2,2); Rcr = ransac.modelcoefficients.block(0,3,2,3); std::cout<<inliers.size()<<std::endl; if(bNonlieanerOpitimize) { opengv::bearingVectors_t bvReferenceNonlinear; opengv::bearingVectors_t bvCurrentNonlinear; for (int i = 0; i < inliers.size(); ++i) { bvReferenceNonlinear.push_back(bvReference[inliers[i]]); bvCurrentNonlinear.push_back(bvCurrent[inliers[i]]); } opengv::relative_pose::CentralRelativeAdapter adapterNolinear( bvReferenceNonlinear, bvCurrentNonlinear,Rcr,Crc); std::cout<<"2.3\n"; opengv::transformation_t nonlinear_transformation = opengv::relative_pose::optimize_nonlinear(adapterNolinear); std::cout<<"2.4\n"; Crc = nonlinear_transformation.block(0,0,2,2); Rcr = nonlinear_transformation.block(0,3,2,3); }`

I use the above code to estimate relative pose of two image, sometimes error occurs in opengv::transformation_t nonlinear_transformation = opengv::relative_pose::optimize_nonlinear(adapterNolinear);

/usr/include/eigen3/Eigen/src/Core/DenseStorage.h:128:Eigen::internal::plain_array<T, Size, MatrixOrArrayOptions, 32>::plain_array() [with T = double; int Size = 12; int MatrixOrArrayOptions = 0]: 假设 ‘(reinterpret_cast( eigen_unaligned_array_assert_workaround_gcc47(array)) & (31)) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily.org/ dox-devel/group__TopicUnalignedArrayAssert.html" " READ THIS WEB PAGE !!! "’ 失败。

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/laurentkneip/opengv/issues/46, or mute the thread https://github.com/notifications/unsubscribe-auth/AAy-Fw4zcACgwC6FgQNvJH6BuFfY9VwQks5ruIEAgaJpZM4M38Xr .

kafeiyin00 commented 7 years ago

Whether a specific version of Eigen is required by openGV?

laurentkneip commented 7 years ago

No. But if you compile the library with one version (including the adapter), and then compile a ransac implementation somewhere else (which is all templated code), and use different eigen versions there, it may possibly produce your error.

I am speculating here, I have not seen this error before. If possible, could you provide a minimal code example so I could try and reproduce the error on my side. Thanks! On 10/04/2017 5:43 PM, "lijianping" notifications@github.com wrote:

Whether a specific version of Eigen is required by openGV?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/laurentkneip/opengv/issues/46#issuecomment-292900413, or mute the thread https://github.com/notifications/unsubscribe-auth/AAy-FzbVb_hbVl7ErdpwGQbcaMNJFIlWks5rufmtgaJpZM4M38Xr .

laurentkneip commented 7 years ago

Anyway, I think you are misunderstanding the format of a transformation in opengv. It is a 3x4 matrix, where the last column is the translation, and the left 3x3 block the rotation. So if you want to extract rotation you have to replace:

Crc = ransac.modelcoefficients.block(0,0,2,2); Rcr = ransac.modelcoefficients.block(0,3,2,3);

by

Crc = ransac.modelcoefficients.block(0,3,3,1); Rcr = ransac.modelcoefficients.block(0,0,3,3);

Also, not that in opengv, the convention is that the resulting transformation transforms points from the camera frame to the world (not sure what the meaning of your indices rc and cr here is!).

kafeiyin00 commented 7 years ago

Thanks a lot!! I think I misunderstand the function block.

kafeiyin00 commented 7 years ago

And I find that when I use the Eigen 3.3.2, the code runs well. But error occurs with the version of 3.3.3