reloc: --slam-reloc-vpr -- camera (VPR TensorRT + PnP) ket hop LiDAR, chot khi hai nguon trung
This commit is contained in:
@@ -20,6 +20,9 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include "vslam/rtabmap_params.h"
|
||||
#include "vslam/slam_types.h"
|
||||
@@ -32,6 +35,15 @@ class RtabmapSlamImpl; // o namespace scope, KHONG long trong class
|
||||
// (pimpl long private khong goi duoc tu .cc -- da
|
||||
// mac loi nay o ConfigNode va WebServer)
|
||||
|
||||
// Anh cua mot node ban do, cho dinh vi lai bang camera (vslam/visual_verifier.h).
|
||||
struct NodeView {
|
||||
cv::Mat gray; // anh IR (kenh "rgb" luc quet), 8 bit
|
||||
cv::Mat depth; // CV_16UC1 (mm); rong neu with_depth = false
|
||||
cv::Matx33d K; // DA bu binning -- dung nhu luc luu
|
||||
cv::Matx44d T_base_optical; // base (z tu san, gom nghieng luc chup) <- optical
|
||||
cv::Matx44d T_map_base; // pose TOI UU cua node
|
||||
};
|
||||
|
||||
class RtabmapSlam {
|
||||
public:
|
||||
RtabmapSlam();
|
||||
@@ -83,6 +95,12 @@ class RtabmapSlam {
|
||||
// chi ho moi biet tap truoc do la gi.
|
||||
StatusResponse ExportVoxels(const VoxelExportOptions& opt, VoxelGrid* out);
|
||||
|
||||
// Node co pose toi uu (ban do dang dung), va anh + hinh hoc camera cua mot node -- DUNG
|
||||
// nhu RTAB-Map da luu (K da bu binning, T gom nghieng luc chup). CHI luong slam goi (cung
|
||||
// luong Process()): doc thang Memory cua RTAB-Map.
|
||||
std::vector<int> MapNodeIds() const;
|
||||
StatusResponse GetNodeView(int id, bool with_depth, NodeView* out);
|
||||
|
||||
StatusResponse Close(bool save_database);
|
||||
|
||||
const SlamStats& stats() const;
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "vslam/rtabmap_slam.h"
|
||||
|
||||
#include <rtabmap/core/Memory.h>
|
||||
#include <rtabmap/core/Optimizer.h>
|
||||
#include <rtabmap/core/Parameters.h>
|
||||
#include <rtabmap/core/Rtabmap.h>
|
||||
#include <rtabmap/core/SensorData.h>
|
||||
#include <rtabmap/core/Statistics.h>
|
||||
#include <rtabmap/utilite/ULogger.h>
|
||||
|
||||
@@ -378,6 +380,48 @@ StatusResponse RtabmapSlam::ExportVoxels(const VoxelExportOptions& opt,
|
||||
return ExportVoxelGrid(impl_->rtabmap, opt, &impl_->voxel_cache, out);
|
||||
}
|
||||
|
||||
namespace {
|
||||
cv::Matx44d ToMatx44(const rtabmap::Transform& t) {
|
||||
return cv::Matx44d(t.r11(), t.r12(), t.r13(), t.x(), t.r21(), t.r22(), t.r23(), t.y(),
|
||||
t.r31(), t.r32(), t.r33(), t.z(), 0, 0, 0, 1);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::vector<int> RtabmapSlam::MapNodeIds() const {
|
||||
std::vector<int> out;
|
||||
if (!impl_->inited) return out;
|
||||
for (const auto& kv : impl_->rtabmap.getLocalOptimizedPoses()) out.push_back(kv.first);
|
||||
return out;
|
||||
}
|
||||
|
||||
StatusResponse RtabmapSlam::GetNodeView(int id, bool with_depth, NodeView* out) {
|
||||
if (!impl_->inited) {
|
||||
return StatusResponse::Error(StatusCode::kFailedPrecondition, "chua init");
|
||||
}
|
||||
const std::map<int, rtabmap::Transform>& poses = impl_->rtabmap.getLocalOptimizedPoses();
|
||||
const auto it = poses.find(id);
|
||||
if (it == poses.end() || it->second.isNull()) {
|
||||
return StatusResponse::Error(StatusCode::kNotFound, "node khong co pose toi uu");
|
||||
}
|
||||
const rtabmap::Memory* mem = impl_->rtabmap.getMemory();
|
||||
if (mem == nullptr) {
|
||||
return StatusResponse::Error(StatusCode::kFailedPrecondition, "rtabmap chua co Memory");
|
||||
}
|
||||
rtabmap::SensorData d = mem->getNodeData(id, true, false, false, false);
|
||||
cv::Mat img, depth;
|
||||
d.uncompressData(&img, with_depth ? &depth : nullptr); // du lieu trong DB la du lieu NEN
|
||||
if (img.empty() || d.cameraModels().empty()) {
|
||||
return StatusResponse::Error(StatusCode::kNotFound, "node khong co anh");
|
||||
}
|
||||
const rtabmap::CameraModel& cm = d.cameraModels()[0];
|
||||
out->gray = img;
|
||||
out->depth = depth;
|
||||
out->K = cv::Matx33d(cm.fx(), 0, cm.cx(), 0, cm.fy(), cm.cy(), 0, 0, 1);
|
||||
out->T_base_optical = ToMatx44(cm.localTransform());
|
||||
out->T_map_base = ToMatx44(it->second);
|
||||
return StatusResponse::Ok();
|
||||
}
|
||||
|
||||
StatusResponse RtabmapSlam::Close(bool save_database) {
|
||||
if (!impl_->inited) return StatusResponse::Ok();
|
||||
impl_->inited = false;
|
||||
|
||||
Reference in New Issue
Block a user