From 2f3f49a6577ae472babac43489d23e27f52b287f Mon Sep 17 00:00:00 2001 From: Timo Schneider Date: Mon, 12 May 2025 10:07:37 +0200 Subject: [PATCH] optimized highlight extractor --- src/pipeline/highlight_extractor.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pipeline/highlight_extractor.rs b/src/pipeline/highlight_extractor.rs index fc5387e..0f0c95f 100644 --- a/src/pipeline/highlight_extractor.rs +++ b/src/pipeline/highlight_extractor.rs @@ -2,7 +2,7 @@ use std::sync::{mpsc, Arc, Mutex}; use std::sync::mpsc::Receiver; use std::thread; use std::time::{Duration, Instant}; -use rand::Rng; +use rand::{rng, Rng}; use r2r::sensor_msgs::msg::Image; pub type Pointcloud = Arc>>; @@ -19,18 +19,16 @@ impl ExtractHighlights for Image { ]; let max_rng = (u32::MAX as f64 * downsample) as u32; + let mut rng = rand::rng(); Arc::new(self.data .iter() - .enumerate() - .filter(|(i, _)| *i as u32 / self.width >= self.height / 2) - .filter(|(_, pixel)| **pixel > threshold) + .enumerate() + .map(|(i, pixel)| (pixel, i as f64 % self.width as f64, i as f64 / self.width as f64)) + .filter(|(pixel, _, _)| **pixel > threshold) .filter(|_| { - let mut rng = rand::rng(); rng.random::() < max_rng }) - .map(|(i, _)| { - let x = i as f64 % self.width as f64; - let y = i as f64 / self.width as f64; + .map(|(_, x, y)| { // Convert to homogeneous coordinates let u = h_i[0][0] * x + h_i[0][1] * y + h_i[0][2];