#include "dls.h"
#include <iostream>
-#include <fstream>
-/*
#ifdef HAVE_EIGEN
# if defined __GNUC__ && defined __APPLE__
# pragma GCC diagnostic ignored "-Wshadow"
# endif
# include <Eigen/Core>
+# include <Eigen/Eigenvalues>
# include "opencv2/core/eigen.hpp"
#endif
-*/
-#include <Eigen/Eigenvalues>
-#include <Eigen/Core>
+
+//#include <Eigen/Eigenvalues>
+//#include <Eigen/Core>
using namespace std;
dls::dls(const cv::Mat& opoints, const cv::Mat& ipoints)
{
+
N = std::max(opoints.checkVector(3, CV_32F), opoints.checkVector(3, CV_64F));
p = cv::Mat(3, N, CV_64F);
z = cv::Mat(3, N, CV_64F);
- cost__ = std::numeric_limits<double>::infinity();
+ cost__ = 9999;
f1coeff.resize(21);
f2coeff.resize(21);
void dls::run_kernel(const cv::Mat& pp)
{
-
cv::Mat Mtilde(27, 27, CV_64F);
cv::Mat D = cv::Mat::zeros(9, 9, CV_64F);
build_coeff_matrix(pp, Mtilde, D);
cv::Mat eigenval_r, eigenval_i, eigenvec_r, eigenvec_i;
compute_eigenvec(Mtilde, eigenval_r, eigenval_i, eigenvec_r, eigenvec_i);
-
/*
* Now check the solutions
*/
cv::Mat V_k; cv::solve(V_kB.t(), V_kA.t(), V_k); // A/B = B'\A'
cv::Mat( V_k.t()).copyTo( eigenvec_r.col(k) );
- // TODO: check imaginari part to filter solutions
-
//if (imag(V(2,k)) == 0)
const double epsilon = 1e-4;
if( eigenval_i.at<double>(k,0) >= -epsilon && eigenval_i.at<double>(k,0) <= epsilon )
cost_.push_back(cost_valid);
}
}
+
}
void dls::build_coeff_matrix(const cv::Mat& pp, cv::Mat& Mtilde, cv::Mat& D)
{
// EIGENVALUES AND EIGENVECTORS
+#ifdef HAVE_EIGEN
Eigen::MatrixXd Mtilde_eig, zeros_eig;
cv::cv2eigen(Mtilde, Mtilde_eig);
cv::cv2eigen(cv::Mat::zeros(27, 27, CV_64F), zeros_eig);
cv::eigen2cv(eigval_imag, eigenval_imag);
cv::eigen2cv(eigvec_real, eigenvec_real);
cv::eigen2cv(eigvec_imag, eigenvec_imag);
+#endif
}
#include <iostream>
using namespace cv;
-void MatrixSize(const cv::Mat& mat)
-{
- cout << mat.rows << "x" << mat.cols << endl;
-}
-
bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
InputArray _cameraMatrix, InputArray _distCoeffs,
OutputArray _rvec, OutputArray _tvec, bool useExtrinsicGuess, int flags )
}
else if (flags == DLS)
{
+ bool result = false;
+#ifdef HAVE_EIGEN
+
cv::Mat undistortedPoints;
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
dls PnP(opoints, undistortedPoints);
cv::Mat R, rvec = _rvec.getMat(), tvec = _tvec.getMat();
- bool result = PnP.compute_pose(R, tvec);
+ result = PnP.compute_pose(R, tvec);
if (result)
cv::Rodrigues(R, rvec);
+#else
+ std::cout << "EIGEN library needed for DLS" << std::endl;
+#endif
return result;
}
else
- CV_Error(CV_StsBadArg, "The flags argument must be one of CV_ITERATIVE, CV_P3P or CV_EPNP");
+ CV_Error(CV_StsBadArg, "The flags argument must be one of CV_ITERATIVE, CV_P3P, CV_EPNP or CV_DLS");
return false;
}