Skip to content

Commit

Permalink
Add collapse option to adder-viz (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
ac-freeman authored Jan 2, 2024
1 parent 2cc4657 commit e217bd8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
8 changes: 5 additions & 3 deletions adder-codec-rs/src/transcoder/source/davis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use crate::transcoder::source::video::SourceError::BufferEmpty;
use crate::transcoder::source::video::{
integrate_for_px, Source, SourceError, Video, VideoBuilder,
};
use adder_codec_core::DeltaT;
use adder_codec_core::Mode::{Continuous, FramePerfect};
use adder_codec_core::{DeltaT, PixelMultiMode};
use davis_edi_rs::aedat::events_generated::Event as DvsEvent;
use davis_edi_rs::util::reconstructor::{IterVal, ReconstructionError, Reconstructor};
use rayon::iter::IndexedParallelIterator;
use rayon::iter::ParallelIterator;
use rayon::iter::{IndexedParallelIterator};

use opencv::core::{Mat, CV_8U};
use opencv::prelude::*;
Expand Down Expand Up @@ -950,7 +950,7 @@ impl<W: Write + 'static + std::marker::Send> Source<W> for Davis<W> {
TranscoderMode::RawDvs => {
let time_mult = 1E6 / self.time_change;
let events_per_sec = self.num_dvs_events as f64 * time_mult;
// Best-case 9 bytes per raw DVS event
// Best-case 9 bytes per raw DVS event
events_per_sec * 9.0 * 8.0
}
}
Expand Down Expand Up @@ -1020,13 +1020,15 @@ impl<W: Write + 'static> VideoBuilder<W> for Davis<W> {
mut self,
source_camera: SourceCamera,
time_mode: TimeMode,
pixel_multi_mode: PixelMultiMode,
encoder_type: EncoderType,
encoder_options: EncoderOptions,
write: W,
) -> Result<Box<Self>, SourceError> {
self.video = self.video.write_out(
Some(source_camera),
Some(time_mode),
Some(pixel_multi_mode),
encoder_type,
encoder_options,
write,
Expand Down
4 changes: 3 additions & 1 deletion adder-codec-rs/src/transcoder/source/framed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::transcoder::source::video::SourceError;
use crate::transcoder::source::video::Video;
use crate::transcoder::source::video::{Source, VideoBuilder};
use adder_codec_core::Mode::FramePerfect;
use adder_codec_core::{DeltaT, Event, PlaneSize, SourceCamera, TimeMode};
use adder_codec_core::{DeltaT, Event, PixelMultiMode, PlaneSize, SourceCamera, TimeMode};

use crate::utils::viz::ShowFeatureMode;
use adder_codec_core::codec::{EncoderOptions, EncoderType};
Expand Down Expand Up @@ -257,13 +257,15 @@ impl<W: Write + 'static> VideoBuilder<W> for Framed<W> {
mut self,
source_camera: SourceCamera,
time_mode: TimeMode,
pixel_multi_mode: PixelMultiMode,
encoder_type: EncoderType,
encoder_options: EncoderOptions,
write: W,
) -> Result<Box<Self>, SourceError> {
self.video = self.video.write_out(
Some(source_camera),
Some(time_mode),
Some(pixel_multi_mode),
encoder_type,
encoder_options,
write,
Expand Down
13 changes: 9 additions & 4 deletions adder-codec-rs/src/transcoder/source/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub enum FramedViewMode {
pub struct VideoStateParams {
pub(crate) pixel_tree_mode: Mode,

pub(crate) pixel_multi_mode: PixelMultiMode,
pub pixel_multi_mode: PixelMultiMode,

/// The maximum time difference between events of the same pixel, in ticks
pub delta_t_max: u32,
Expand Down Expand Up @@ -303,6 +303,7 @@ pub trait VideoBuilder<W> {
self,
source_camera: SourceCamera,
time_mode: TimeMode,
pixel_multi_mode: PixelMultiMode,
encoder_type: EncoderType,
encoder_options: EncoderOptions,
write: W,
Expand Down Expand Up @@ -544,6 +545,7 @@ impl<W: Write + 'static> Video<W> {
mut self,
source_camera: Option<SourceCamera>,
time_mode: Option<TimeMode>,
pixel_multi_mode: Option<PixelMultiMode>,
encoder_type: EncoderType,
encoder_options: EncoderOptions,
write: W,
Expand All @@ -552,7 +554,8 @@ impl<W: Write + 'static> Video<W> {
EncoderType::Compressed => {
#[cfg(feature = "compression")]
{
self.state.params.pixel_multi_mode = PixelMultiMode::Collapse;
self.state.params.pixel_multi_mode =
pixel_multi_mode.unwrap_or(PixelMultiMode::Collapse);
let compression = CompressedOutput::new(
CodecMetadata {
codec_version: LATEST_CODEC_VERSION,
Expand All @@ -578,7 +581,8 @@ impl<W: Write + 'static> Video<W> {
}
}
EncoderType::Raw => {
self.state.params.pixel_multi_mode = PixelMultiMode::Collapse;
self.state.params.pixel_multi_mode =
pixel_multi_mode.unwrap_or(PixelMultiMode::Collapse);
let compression = RawOutput::new(
CodecMetadata {
codec_version: LATEST_CODEC_VERSION,
Expand All @@ -596,7 +600,8 @@ impl<W: Write + 'static> Video<W> {
Encoder::new_raw(compression, encoder_options)
}
EncoderType::Empty => {
self.state.params.pixel_multi_mode = PixelMultiMode::Collapse;
self.state.params.pixel_multi_mode =
pixel_multi_mode.unwrap_or(PixelMultiMode::Collapse);
let compression = EmptyOutput::new(
CodecMetadata {
codec_version: LATEST_CODEC_VERSION,
Expand Down
2 changes: 2 additions & 0 deletions adder-viz/src/transcoder/adder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl AdderTranscoder {
framed = *framed.write_out(
FramedU8,
ui_state.time_mode,
ui_state.integration_mode_radio_state,
ui_state.encoder_type,
ui_state.encoder_options,
writer,
Expand Down Expand Up @@ -219,6 +220,7 @@ impl AdderTranscoder {
davis_source = *davis_source.write_out(
DavisU8,
ui_state.time_mode,
ui_state.integration_mode_radio_state,
ui_state.encoder_type,
ui_state.encoder_options,
writer,
Expand Down
23 changes: 21 additions & 2 deletions adder-viz/src/transcoder/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use std::error::Error;
use crate::utils::PlotY;
use adder_codec_rs::adder_codec_core::codec::rate_controller::{Crf, CRF, DEFAULT_CRF_QUALITY};
use adder_codec_rs::adder_codec_core::codec::{EncoderOptions, EncoderType, EventDrop, EventOrder};
use adder_codec_rs::adder_codec_core::PlaneSize;
use adder_codec_rs::adder_codec_core::TimeMode;
use adder_codec_rs::adder_codec_core::{PixelMultiMode, PlaneSize};
#[cfg(feature = "open-cv")]
use adder_codec_rs::transcoder::source::davis::TranscoderMode::RawDvs;
use adder_codec_rs::utils::cv::{calculate_quality_metrics, QualityMetrics};
Expand Down Expand Up @@ -69,6 +69,7 @@ pub struct ParamsUiState {
metric_mse: bool,
metric_psnr: bool,
metric_ssim: bool,
pub(crate) integration_mode_radio_state: PixelMultiMode,
}

impl Default for ParamsUiState {
Expand Down Expand Up @@ -113,6 +114,7 @@ impl Default for ParamsUiState {
metric_mse: true,
metric_psnr: true,
metric_ssim: false,
integration_mode_radio_state: Default::default(),
}
}
}
Expand Down Expand Up @@ -448,7 +450,9 @@ impl TranscoderState {
|| source.get_video_ref().get_encoder_options().event_drop
!= self.ui_state.encoder_options.event_drop
|| source.get_video_ref().get_encoder_options().event_order
!= self.ui_state.encoder_options.event_order)
!= self.ui_state.encoder_options.event_order
|| source.get_video_ref().state.params.pixel_multi_mode
!= self.ui_state.integration_mode_radio_state)
&& self.ui_info_state.output_path.is_some())
{
if self.ui_state.davis_mode_radio_state == RawDvs {
Expand Down Expand Up @@ -880,6 +884,21 @@ fn side_panel_grid_contents(
ui.add_enabled(enabled, egui::Checkbox::new(&mut ui_state.color, "Color?"));
ui.end_row();

ui.label("Integration mode:");
ui.horizontal(|ui| {
ui.radio_value(
&mut ui_state.integration_mode_radio_state,
PixelMultiMode::Normal,
"Normal",
);
ui.radio_value(
&mut ui_state.integration_mode_radio_state,
PixelMultiMode::Collapse,
"Collapse",
);
});
ui.end_row();

ui.label("View mode:");
ui.vertical(|ui| {
ui.horizontal(|ui| {
Expand Down

0 comments on commit e217bd8

Please sign in to comment.