fixed compilation errors in epnp with gcc
This commit is contained in:
parent
c5d8ec4ac0
commit
6fa936472e
@ -2,37 +2,41 @@
|
||||
using namespace std;
|
||||
#include "precomp.hpp"
|
||||
#include "epnp.h"
|
||||
|
||||
namespace cv
|
||||
|
||||
namespace cv
|
||||
{
|
||||
double ePnP( InputArray _opoints, InputArray _ipoints,
|
||||
InputArray _cameraMatrix, InputArray _distCoeffs,
|
||||
OutputArray _rvec, OutputArray _tvec)
|
||||
{
|
||||
Mat opoints = _opoints.getMat(), ipoints = _ipoints.getMat();
|
||||
int npoints = std::max(opoints.checkVector(3, CV_32F), opoints.checkVector(3, CV_64F));
|
||||
CV_Assert( npoints >= 0 && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) );
|
||||
Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat();
|
||||
|
||||
Mat undistortedPoints;
|
||||
undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
|
||||
double ePnP( InputArray _opoints, InputArray _ipoints,
|
||||
InputArray _cameraMatrix, InputArray _distCoeffs,
|
||||
OutputArray _rvec, OutputArray _tvec)
|
||||
{
|
||||
Mat opoints = _opoints.getMat(), ipoints = _ipoints.getMat();
|
||||
int npoints = std::max(opoints.checkVector(3, CV_32F), opoints.checkVector(3, CV_64F));
|
||||
CV_Assert( npoints >= 0 && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) );
|
||||
Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat();
|
||||
|
||||
Mat undistortedPoints;
|
||||
undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
|
||||
epnp PnP;
|
||||
PnP.set_internal_parameters(cameraMatrix.at<double> (0, 2), cameraMatrix.at<double> (1, 2), cameraMatrix.at<double> (0, 0), cameraMatrix.at<double> (1, 1));
|
||||
PnP.set_maximum_number_of_correspondences(npoints);
|
||||
PnP.set_maximum_number_of_correspondences(npoints);
|
||||
PnP.reset_correspondences();
|
||||
for(int i = 0; i < npoints; i++) {
|
||||
PnP.add_correspondence(opoints.at<Point3d>(0,i).x, opoints.at<Point3d>(0,i).y, opoints.at<Point3d>(0,i).z, undistortedPoints.at<Point2d>(0,i).x* cameraMatrix.at<double> (0, 0) + cameraMatrix.at<double> (0, 2),
|
||||
undistortedPoints.at<Point2d>(0,i).y* cameraMatrix.at<double> (1, 1) + cameraMatrix.at<double> (1, 2));
|
||||
}
|
||||
}
|
||||
double R_est[3][3], t_est[3];
|
||||
double error = PnP.compute_pose(R_est, t_est);
|
||||
|
||||
_tvec.create(3,1,CV_64F);
|
||||
_rvec.create(3,1,CV_64F);
|
||||
Mat(3, 1, CV_64FC1, t_est).copyTo(_tvec.getMat());
|
||||
Rodrigues(Mat(3, 3, CV_64FC1, R_est), _rvec.getMat());
|
||||
return error;
|
||||
double error = PnP.compute_pose(R_est, t_est);
|
||||
|
||||
_tvec.create(3,1,CV_64F);
|
||||
_rvec.create(3,1,CV_64F);
|
||||
Mat t = Mat(3, 1, CV_64FC1, t_est);
|
||||
Mat tvec = _tvec.getMat();
|
||||
t.copyTo(tvec);
|
||||
Mat R = Mat(3, 3, CV_64FC1, R_est);
|
||||
Mat rvec = _rvec.getMat();
|
||||
Rodrigues(R, rvec);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user