mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-02 09:30:25 +08:00
fix build errors with opencv2, added Transform::getClosestTransform() function for convenience.
This commit is contained in:
@@ -65,7 +65,6 @@ public:
|
|||||||
return localTransform_.isNull();
|
return localTransform_.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cv::Vec4d orientation_;
|
cv::Vec4d orientation_;
|
||||||
cv::Mat orientationCovariance_; // 3x3 double Row major about x, y, z axes, empty if orientation is not set
|
cv::Mat orientationCovariance_; // 3x3 double Row major about x, y, z axes, empty if orientation is not set
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <rtabmap/core/RtabmapExp.h>
|
#include <rtabmap/core/RtabmapExp.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <map>
|
||||||
#include <Eigen/Core>
|
#include <Eigen/Core>
|
||||||
#include <Eigen/Geometry>
|
#include <Eigen/Geometry>
|
||||||
#include <opencv2/core/core.hpp>
|
#include <opencv2/core/core.hpp>
|
||||||
@@ -149,6 +150,11 @@ public:
|
|||||||
static Transform fromString(const std::string & string);
|
static Transform fromString(const std::string & string);
|
||||||
static bool canParseString(const std::string & string);
|
static bool canParseString(const std::string & string);
|
||||||
|
|
||||||
|
static Transform getClosestTransform(
|
||||||
|
const std::map<double, Transform> & tfBuffer,
|
||||||
|
const double & stamp,
|
||||||
|
double * stampDiff = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cv::Mat data_;
|
cv::Mat data_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
virtual Transform computeTransform(SensorData & data, const Transform & guess = Transform(), OdometryInfo * info = 0);
|
virtual Transform computeTransform(SensorData & data, const Transform & guess = Transform(), OdometryInfo * info = 0);
|
||||||
Transform getClosestIMU(const double & stamp, double & stampDiff) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//Parameters
|
//Parameters
|
||||||
|
|||||||
@@ -467,4 +467,41 @@ bool Transform::canParseString(const std::string & string)
|
|||||||
return list.size() == 0 || list.size() == 3 || list.size() == 6 || list.size() == 7 || list.size() == 9 || list.size() == 12;
|
return list.size() == 0 || list.size() == 3 || list.size() == 6 || list.size() == 7 || list.size() == 9 || list.size() == 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Transform Transform::getClosestTransform(
|
||||||
|
const std::map<double, Transform> & tfBuffer,
|
||||||
|
const double & stamp,
|
||||||
|
double * stampDiff)
|
||||||
|
{
|
||||||
|
UASSERT(!tfBuffer.empty());
|
||||||
|
std::map<double, Transform>::const_iterator imuIterB = tfBuffer.lower_bound(stamp);
|
||||||
|
std::map<double, Transform>::const_iterator imuIterA = imuIterB;
|
||||||
|
if(imuIterA != tfBuffer.begin())
|
||||||
|
{
|
||||||
|
imuIterA = --imuIterA;
|
||||||
|
}
|
||||||
|
if(imuIterB == tfBuffer.end())
|
||||||
|
{
|
||||||
|
imuIterB = --imuIterB;
|
||||||
|
}
|
||||||
|
Transform imuT;
|
||||||
|
if(imuIterB->first == stamp || imuIterA == imuIterB)
|
||||||
|
{
|
||||||
|
imuT = imuIterB->second;
|
||||||
|
if(stampDiff)
|
||||||
|
{
|
||||||
|
*stampDiff = fabs(imuIterB->first - stamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(imuIterA != imuIterB)
|
||||||
|
{
|
||||||
|
//interpolate:
|
||||||
|
imuT = imuIterA->second.interpolate((stamp-imuIterA->first) / (imuIterB->first-imuIterA->first), imuIterB->second);
|
||||||
|
if(stampDiff)
|
||||||
|
{
|
||||||
|
*stampDiff = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return imuT;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <rtabmap/utilite/UConversion.h>
|
#include <rtabmap/utilite/UConversion.h>
|
||||||
#if CV_MAJOR_VERSION > 3
|
#if CV_MAJOR_VERSION > 3
|
||||||
#include <opencv2/videoio/videoio_c.h>
|
#include <opencv2/videoio/videoio_c.h>
|
||||||
|
#if CV_MAJOR_VERSION > 4
|
||||||
|
#include <opencv2/videoio/legacy/constants_c.h>
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace rtabmap
|
namespace rtabmap
|
||||||
@@ -131,13 +134,13 @@ bool CameraVideo::init(const std::string & calibrationFolder, const std::string
|
|||||||
{
|
{
|
||||||
if(_model.isValidForProjection())
|
if(_model.isValidForProjection())
|
||||||
{
|
{
|
||||||
_capture.set(cv::CAP_PROP_FRAME_WIDTH, _model.imageWidth());
|
_capture.set(CV_CAP_PROP_FRAME_WIDTH, _model.imageWidth());
|
||||||
_capture.set(cv::CAP_PROP_FRAME_HEIGHT, _model.imageHeight());
|
_capture.set(CV_CAP_PROP_FRAME_HEIGHT, _model.imageHeight());
|
||||||
}
|
}
|
||||||
else if(_width > 0 && _height > 0)
|
else if(_width > 0 && _height > 0)
|
||||||
{
|
{
|
||||||
_capture.set(cv::CAP_PROP_FRAME_WIDTH, _width);
|
_capture.set(CV_CAP_PROP_FRAME_WIDTH, _width);
|
||||||
_capture.set(cv::CAP_PROP_FRAME_HEIGHT, _height);
|
_capture.set(CV_CAP_PROP_FRAME_HEIGHT, _height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(_rectifyImages && !_model.isValidForRectification())
|
if(_rectifyImages && !_model.isValidForRectification())
|
||||||
|
|||||||
@@ -335,8 +335,7 @@ Transform OdometryF2M::computeTransform(
|
|||||||
Transform imuT;
|
Transform imuT;
|
||||||
if(!imus_.empty())
|
if(!imus_.empty())
|
||||||
{
|
{
|
||||||
double stampDiff = 0.0;
|
imuT = Transform::getClosestTransform(imus_, lastFrame_->getStamp());
|
||||||
imuT = getClosestIMU(lastFrame_->getStamp(), stampDiff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// local bundle adjustment
|
// local bundle adjustment
|
||||||
@@ -1304,43 +1303,4 @@ Transform OdometryF2M::computeTransform(
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform OdometryF2M::getClosestIMU(const double & stamp, double & stampDiff) const
|
|
||||||
{
|
|
||||||
UASSERT(!imus_.empty());
|
|
||||||
std::map<double, Transform>::const_iterator imuIterB = imus_.lower_bound(stamp);
|
|
||||||
std::map<double, Transform>::const_iterator imuIterA = imuIterB;
|
|
||||||
if(imuIterA != imus_.begin())
|
|
||||||
{
|
|
||||||
imuIterA = --imuIterA;
|
|
||||||
}
|
|
||||||
if(imuIterB == imus_.end())
|
|
||||||
{
|
|
||||||
imuIterB = --imuIterB;
|
|
||||||
}
|
|
||||||
Transform imuT;
|
|
||||||
stampDiff = 0.0;
|
|
||||||
if(imuIterB->first == lastFrame_->getStamp() || imuIterA == imuIterB)
|
|
||||||
{
|
|
||||||
imuT = imuIterB->second;
|
|
||||||
stampDiff = fabs(imuIterB->first - lastFrame_->getStamp());
|
|
||||||
}
|
|
||||||
else if(imuIterA != imuIterB)
|
|
||||||
{
|
|
||||||
if(fabs(imuIterA->first - lastFrame_->getStamp()) <
|
|
||||||
fabs(imuIterB->first - lastFrame_->getStamp()))
|
|
||||||
{
|
|
||||||
//imuT = imuIterA->second;
|
|
||||||
stampDiff = fabs(imuIterA->first - lastFrame_->getStamp());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//imuT = imuIterB->second;
|
|
||||||
stampDiff = fabs(imuIterB->first - lastFrame_->getStamp());
|
|
||||||
}
|
|
||||||
//interpolate:
|
|
||||||
imuT = imuIterA->second.interpolate((stamp-imuIterA->first) / (imuIterB->first-imuIterA->first), imuIterB->second);
|
|
||||||
}
|
|
||||||
return imuT;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace rtabmap
|
} // namespace rtabmap
|
||||||
|
|||||||
@@ -439,9 +439,7 @@ int main(int argc, char * argv[])
|
|||||||
|
|
||||||
SensorData dataImu(IMU(gyr, cv::Mat(3,3,CV_64FC1), acc, cv::Mat(3,3,CV_64FC1), baseToImu), 0, t_imu);
|
SensorData dataImu(IMU(gyr, cv::Mat(3,3,CV_64FC1), acc, cv::Mat(3,3,CV_64FC1), baseToImu), 0, t_imu);
|
||||||
cameraThread.postUpdate(&dataImu);
|
cameraThread.postUpdate(&dataImu);
|
||||||
UDEBUG("");
|
|
||||||
odom->process(dataImu);
|
odom->process(dataImu);
|
||||||
UDEBUG("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (t_imu <= data.stamp());
|
} while (t_imu <= data.stamp());
|
||||||
|
|||||||
Reference in New Issue
Block a user