update
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
// VoxelAccumulator va DiffVoxelGrids: phan THUAN cua duong xuat ban do 3D.
|
||||
//
|
||||
// Khong mot kieu nao cua RTAB-Map o day, va do la chu y: `ExportOccupancyGrid`
|
||||
// Khong can mot `Rtabmap` dang chay, va do la chu y: `ExportOccupancyGrid`
|
||||
// den nay khong co unit test nao chinh vi no can mot `Rtabmap` dang chay.
|
||||
// Phan tinh toan tach ra thi kiem duoc bang so.
|
||||
// Phan tinh toan tach ra thi kiem duoc bang so. Test NodeCloud o cuoi dung
|
||||
// kieu RTAB-Map (SensorData, CameraModel) nhung tu dung, khong can Rtabmap.
|
||||
|
||||
#include "vslam/voxel_export.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <rtabmap/core/CameraModel.h>
|
||||
#include <rtabmap/core/SensorData.h>
|
||||
#include <rtabmap/core/Transform.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
@@ -107,16 +112,44 @@ TEST(VoxelAccumulator, DauRaDaSapXep) {
|
||||
EXPECT_TRUE(DaSapXep(g.cells)) << "DiffVoxelGrids dua vao dung tinh chat nay";
|
||||
}
|
||||
|
||||
TEST(VoxelAccumulator, ChamTranThiCatVaBaoTruncated) {
|
||||
TEST(VoxelAccumulator, ChamTranThiGiamMauDeuChuKhongCatCut) {
|
||||
// ⚠️ Bai kiem NAY la bai kiem quan trong nhat trong file.
|
||||
//
|
||||
// Ban dau Finish() lay `max_cells` phan tu DAU cua danh sach da sort. Khoa
|
||||
// sort theo x truoc, nen no chat mot LAT KHONG GIAN: nguyen mot canh cua toa
|
||||
// nha bien mat trong khi phan con lai van day du. Nguoi dung phat hien bang
|
||||
// mat ("goc tren ben trai quet roi ma gio mat"), khong mot log nao bao.
|
||||
//
|
||||
// Bat bien phai giu: ban do MONG di deu, KHONG cut mot dau.
|
||||
VoxelExportOptions o = Opt(0.10);
|
||||
o.max_cells = 4;
|
||||
o.max_cells = 5;
|
||||
VoxelAccumulator acc(o);
|
||||
for (int i = 0; i < 20; ++i) acc.AddPoint(i * 1.0, 0.0, 1.0); // x = 0..19 m
|
||||
VoxelGrid g;
|
||||
acc.Finish(&g);
|
||||
|
||||
EXPECT_TRUE(g.truncated) << "giam mau ma khong bao la kieu hong te nhat";
|
||||
EXPECT_EQ(acc.stride(), 4u); // ceil(20 / 5)
|
||||
ASSERT_EQ(g.cells.size(), 5u);
|
||||
|
||||
// Chi so = met / 0.05... o day emit 0.10 nen x = 0, 4, 8, 12, 16 m -> 0, 40,
|
||||
// 80, 120, 160. Hai DAU deu con: do la dieu phep cat cut khong lam duoc.
|
||||
EXPECT_EQ(g.cells.front().x, 0) << "mat dau ban do";
|
||||
EXPECT_EQ(g.cells.back().x, 160) << "mat duoi ban do -- dung loi cu quay lai";
|
||||
EXPECT_TRUE(DaSapXep(g.cells)) << "giam mau khong duoc pha thu tu";
|
||||
}
|
||||
|
||||
TEST(VoxelAccumulator, DuoiTranThiKhongDongGi) {
|
||||
VoxelExportOptions o = Opt(0.10);
|
||||
o.max_cells = 1000;
|
||||
VoxelAccumulator acc(o);
|
||||
for (int i = 0; i < 20; ++i) acc.AddPoint(i * 1.0, 0.0, 1.0);
|
||||
VoxelGrid g;
|
||||
acc.Finish(&g);
|
||||
|
||||
EXPECT_EQ(g.cells.size(), 4u);
|
||||
EXPECT_TRUE(g.truncated) << "cat bot ma khong bao la kieu hong te nhat";
|
||||
EXPECT_EQ(g.cells.size(), 20u);
|
||||
EXPECT_FALSE(g.truncated);
|
||||
EXPECT_EQ(acc.stride(), 1u);
|
||||
}
|
||||
|
||||
TEST(VoxelAccumulator, FlushNhieuLanVanRaCungKetQua) {
|
||||
@@ -208,3 +241,38 @@ TEST(DiffVoxelGrids, SauVongDongThiDoiGanHet) {
|
||||
static_cast<double>(now.size());
|
||||
EXPECT_GT(ratio, 0.35) << "vuot nguong -> nguoi goi phai doi epoch";
|
||||
}
|
||||
|
||||
TEST(NodeCloud, DepthRaDiemOFrameBase) {
|
||||
// Tuong phang cach camera 2 m; camera cao 0.36 m so voi base, nhin +x.
|
||||
// Diem phai co x ~ 2 (frame base), KHONG phai z ~ 2 (frame quang hoc) --
|
||||
// ca ban do 3D dua vao gia thiet cloudFromSensorData ap localTransform.
|
||||
const int w = 64, h = 48;
|
||||
cv::Mat depth(h, w, CV_32FC1, cv::Scalar(2.0f));
|
||||
cv::Mat gray = cv::Mat::zeros(h, w, CV_8UC1);
|
||||
const rtabmap::Transform base_to_optical =
|
||||
rtabmap::Transform(0, 0, 0.36f, 0, 0, 0) *
|
||||
rtabmap::CameraModel::opticalRotation();
|
||||
rtabmap::CameraModel model(50.0, 50.0, w / 2.0, h / 2.0, base_to_optical,
|
||||
0.0, cv::Size(w, h));
|
||||
rtabmap::SensorData data(gray, depth, model, 1, 0.0);
|
||||
|
||||
VoxelExportOptions opt = Opt(0.05);
|
||||
opt.depth_decimation = 1;
|
||||
std::vector<float> pts;
|
||||
NodeCloudFromSensorData(data, opt, &pts);
|
||||
ASSERT_FALSE(pts.empty());
|
||||
ASSERT_EQ(pts.size() % 3, 0u);
|
||||
for (size_t i = 0; i < pts.size(); i += 3) {
|
||||
EXPECT_NEAR(pts[i], 2.0, opt.emit_size_m);
|
||||
EXPECT_GE(pts[i + 2], opt.z_min - opt.emit_size_m);
|
||||
EXPECT_LE(pts[i + 2], opt.z_max + opt.emit_size_m);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(NodeCloud, KhongCoDepthThiRong) {
|
||||
// Node quet voi camera_3d=false: khong co depth -> rong, khong nem loi.
|
||||
rtabmap::SensorData data;
|
||||
std::vector<float> pts{1.0f, 2.0f, 3.0f};
|
||||
NodeCloudFromSensorData(data, Opt(0.05), &pts);
|
||||
EXPECT_TRUE(pts.empty());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user