Skip to content

Commit

Permalink
multi cam pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarriba committed Dec 29, 2024
1 parent 9929ab3 commit 2a079e7
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
10 changes: 7 additions & 3 deletions examples/copper_pipeline/kornia_app.ron
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
id: "rerun",
type: "copper::tasks::rerun_viz::RerunViz",
),
],
//(
// id: "sobel",
// type: "copper::tasks::sobel::Sobel",
//),
],
cnx: [
(src: "cam", dst: "rerun", msg: "copper::tasks::ImageRGBU8Msg"),
(src: "cam_garden", dst: "rerun", msg: "copper::tasks::ImageRGBU8Msg"),
(src: "cam_garden", dst: "rerun", msg: "copper::tasks::ImageRGBU8Msg"),
(src: "cam", dst: "rerun", msg: "copper::tasks::ImageRGBU8Msg"),
],
logging: (
slab_size_mib: 1024, // Preallocates 1GiB of memory map file at a time
Expand Down
6 changes: 6 additions & 0 deletions examples/copper_pipeline/src/tasks/cu_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ pub struct ImageGrayU8Msg {
pub image: ImageGrayU8,
}

impl std::fmt::Debug for ImageGrayU8Msg {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ImageGrayU8Msg(size: {:?})", self.image.size())
}
}

impl Default for ImageGrayU8Msg {
fn default() -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion examples/copper_pipeline/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ pub mod sobel;
pub mod webcam;

mod cu_image;
pub use cu_image::ImageRGBU8Msg;
pub use cu_image::{ImageGrayU8Msg, ImageRGBU8Msg};
31 changes: 26 additions & 5 deletions examples/copper_pipeline/src/tasks/rerun_viz.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cu29::prelude::*;

use super::cu_image::ImageRGBU8Msg;
use super::cu_image::{ImageGrayU8Msg, ImageRGBU8Msg};

pub struct RerunViz {
rec: rerun::RecordingStream,
Expand All @@ -23,21 +23,25 @@ impl<'cl> CuSinkTask<'cl> for RerunViz {
}

fn process(&mut self, _clock: &RobotClock, input: Self::Input) -> Result<(), CuError> {
let (img1, img2) = input;
let (img2, img1) = input;

if let Some(img) = img1.payload() {
log_image(&self.rec, "webcam", &img)?;
log_image_rgb(&self.rec, "webcam", &img)?;
}

if let Some(img) = img2.payload() {
log_image(&self.rec, "garden", &img)?;
log_image_rgb(&self.rec, "garden", &img)?;
}

Ok(())
}
}

fn log_image(rec: &rerun::RecordingStream, name: &str, img: &ImageRGBU8Msg) -> Result<(), CuError> {
fn log_image_rgb(
rec: &rerun::RecordingStream,
name: &str,
img: &ImageRGBU8Msg,
) -> Result<(), CuError> {
rec.log(
name,
&rerun::Image::from_elements(
Expand All @@ -49,3 +53,20 @@ fn log_image(rec: &rerun::RecordingStream, name: &str, img: &ImageRGBU8Msg) -> R
.map_err(|e| CuError::new_with_cause("Failed to log image", e))?;
Ok(())
}

fn log_image_gray(

Check warning on line 57 in examples/copper_pipeline/src/tasks/rerun_viz.rs

View workflow job for this annotation

GitHub Actions / Check

function `log_image_gray` is never used

Check warning on line 57 in examples/copper_pipeline/src/tasks/rerun_viz.rs

View workflow job for this annotation

GitHub Actions / Test Suite - i686-unknown-linux-gnu

function `log_image_gray` is never used

Check warning on line 57 in examples/copper_pipeline/src/tasks/rerun_viz.rs

View workflow job for this annotation

GitHub Actions / Test Suite - x86_64-unknown-linux-gnu

function `log_image_gray` is never used

Check warning on line 57 in examples/copper_pipeline/src/tasks/rerun_viz.rs

View workflow job for this annotation

GitHub Actions / Test Suite - aarch64-unknown-linux-gnu

function `log_image_gray` is never used
rec: &rerun::RecordingStream,
name: &str,
img: &ImageGrayU8Msg,
) -> Result<(), CuError> {
rec.log(
name,
&rerun::Image::from_elements(
img.image.as_slice(),
img.image.size().into(),
rerun::ColorModel::L,
),
)
.map_err(|e| CuError::new_with_cause("Failed to log image", e))?;
Ok(())
}
31 changes: 26 additions & 5 deletions examples/copper_pipeline/src/tasks/sobel.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use cu29::prelude::*;
use kornia::imgproc;
use kornia::{image::Image, imgproc};

use super::cu_image::ImageRGBU8Msg;
use super::cu_image::{ImageGrayU8Msg, ImageRGBU8Msg};

pub struct Sobel;

impl Freezable for Sobel {}

impl<'cl> CuTask<'cl> for Sobel {
type Input = input_msg!('cl, ImageRGBU8Msg);
type Output = output_msg!('cl, ImageRGBU8Msg);
type Output = output_msg!('cl, ImageGrayU8Msg);

fn new(config: Option<&ComponentConfig>) -> Result<Self, CuError>
fn new(_config: Option<&ComponentConfig>) -> Result<Self, CuError>
where
Self: Sized,
{
Expand All @@ -36,7 +36,28 @@ impl<'cl> CuTask<'cl> for Sobel {
return Ok(());
};

let dst = imgproc::filters::sobel(src, kornia::core::types::BorderType::REPLICATE);
println!("src: {:?}", src.image.size());

let img = src
.image
.channel(0)
.map_err(|e| CuError::new_with_cause("Failed to get channel", e))?;

let img_f32 = img
.cast_and_scale(1.0f32 / 255.0f32)
.map_err(|e| CuError::new_with_cause("Failed to cast image", e))?;

let mut img_sobel = Image::from_size_val(img_f32.size(), 0.0f32)
.map_err(|e| CuError::new_with_cause("Failed to create image", e))?;

imgproc::filter::sobel(&img_f32, &mut img_sobel, 3)
.map_err(|e| CuError::new_with_cause("Failed to apply sobel", e))?;

let dst = img_sobel
.scale_and_cast::<u8>(255.0f32)
.map_err(|e| CuError::new_with_cause("Failed to cast image", e))?;

output.set_payload(ImageGrayU8Msg { image: dst });

Ok(())
}
Expand Down

0 comments on commit 2a079e7

Please sign in to comment.