Skip to content

Commit 77dd5e5

Browse files
Move the normalization of the timestamps in preprocessing (#433)
* Normalize timestamps * Format * more explicit * Simplify generic dataloader * Fix mcap reader * Simplify * Normalizization happen in pipeline * Forgot that timestamps can be empty * Fix pipeline * Do not use C++ 20 features * Remove warning of unused argument --------- Co-authored-by: Benedikt Mersch <[email protected]>
1 parent a2b8f13 commit 77dd5e5

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

cpp/kiss_icp/core/Preprocessing.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ std::vector<Eigen::Vector3d> Preprocessor::Preprocess(const std::vector<Eigen::V
5959
if (!deskew_ || timestamps.empty()) {
6060
return frame;
6161
} else {
62+
const auto &[min, max] = std::minmax_element(timestamps.cbegin(), timestamps.cend());
63+
const double min_time = *min;
64+
const double max_time = *max;
65+
const auto normalize = [&](const double t) {
66+
return (t - min_time) / (max_time - min_time);
67+
};
6268
const auto &omega = relative_motion.log();
6369
std::vector<Eigen::Vector3d> deskewed_frame(frame.size());
6470
tbb::parallel_for(
@@ -68,7 +74,7 @@ std::vector<Eigen::Vector3d> Preprocessor::Preprocess(const std::vector<Eigen::V
6874
[&](const tbb::blocked_range<size_t> &r) {
6975
for (size_t idx = r.begin(); idx < r.end(); ++idx) {
7076
const auto &point = frame.at(idx);
71-
const auto &stamp = timestamps.at(idx);
77+
const auto &stamp = normalize(timestamps.at(idx));
7278
const auto pose = Sophus::SE3d::exp((stamp - 1.0) * omega);
7379
deskewed_frame.at(idx) = pose * point;
7480
};

python/kiss_icp/datasets/generic.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,7 @@ def __init__(self, time_field):
103103
if self.time_field is None:
104104
self.get_timestamps = lambda _: np.array([])
105105
else:
106-
self.get_timestamps = lambda pcd: self.min_max_normalize(
107-
pcd.point[self.time_field].numpy().ravel()
108-
)
109-
110-
def min_max_normalize(self, data):
111-
return (data - np.min(data)) / (np.max(data) - np.min(data))
106+
self.get_timestamps = lambda pcd: pcd.point[self.time_field].numpy().ravel()
112107

113108
def __call__(self, file):
114109
pcd = o3d.t.io.read_point_cloud(file)

python/kiss_icp/datasets/mcap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __del__(self):
6060
def __getitem__(self, idx):
6161
msg = next(self.msgs).ros_msg
6262
self.timestamps.append(self.stamp_to_sec(msg.header.stamp))
63-
return self.read_point_cloud(msg), np.array([])
63+
return self.read_point_cloud(msg)
6464

6565
def __len__(self):
6666
return self.n_scans

python/kiss_icp/tools/point_cloud2.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ def read_point_cloud(msg: PointCloud2) -> Tuple[np.ndarray, np.ndarray]:
8282

8383
if t_field:
8484
timestamps = points_structured[t_field].astype(np.float64)
85-
min_timestamp = np.min(timestamps)
86-
max_timestamp = np.max(timestamps)
87-
timestamps = (timestamps - min_timestamp) / (max_timestamp - min_timestamp)
8885
else:
8986
timestamps = np.array([])
9087
return points.astype(np.float64), timestamps

0 commit comments

Comments
 (0)