Skip to content

Commit 3f0d5da

Browse files
authored
Crf quality (#70)
* Begin setting up naive CRF quality parameter * Integrate the CRF parameter in adder-viz * Add a plot to show the live count of events PPC * Improve setting of threshold parameters with viz * Get a test passing again * All tests passing * Deprecate c_thresh functions * Add legend to plot * Setup for feature testing on player * Move feature detection & drawing functions out to utils * Move feature detection & drawing functions out to utils * Simplify cargo deps * Some cleanup * Some cleanup * Start feature detection in player * Begin implementing feature detection on the player side * Bugfix for writing out to file * Don't needlessly slow down when selecting a new encoder type (before selecting the output path) * Better feature detection on player, but not great yet * Much better feature detection on player * Optimizations * Fixes for standalone player * More fixes for standalone player * Also fix fast mode in adder-viz * Tests passing
1 parent 3cb6cb3 commit 3f0d5da

File tree

28 files changed

+958
-348
lines changed

28 files changed

+958
-348
lines changed

.idea/adder-codec-rs.iml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Test_stable.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/adder_video_player.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adder-codec-core/src/codec/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,38 @@ use enum_dispatch::enum_dispatch;
77
use std::io;
88
use std::io::{Read, Seek, Sink, Write};
99

10+
/// Different options for what to with the events we're given
1011
#[enum_dispatch(WriteCompression<W>)]
1112
pub enum WriteCompressionEnum<W: Write> {
13+
/// Perform (possibly lossy) compression on the ADΔER stream, and arithmetic coding
1214
#[cfg(feature = "compression")]
1315
CompressedOutput(CompressedOutput<W>),
16+
17+
/// Write the ADΔER stream as raw events
1418
RawOutput(RawOutput<W>),
19+
20+
/// Write the ADΔER stream as raw events, but make sure that they are ordered perfectly according
21+
/// to their firing times
1522
RawOutputInterleaved(RawOutputInterleaved<W>),
23+
24+
/// Do not write any data to the output stream
1625
EmptyOutput(EmptyOutput<Sink>),
1726
}
1827

19-
#[derive(Default, Clone, Copy, PartialEq)]
28+
/// Specifies the output type of the encoder
29+
#[derive(Default, Clone, Copy, PartialEq, Debug)]
2030
pub enum EncoderType {
31+
/// Perform (possibly lossy) compression on the ADΔER stream, and arithmetic coding
2132
Compressed,
33+
34+
/// Write the ADΔER stream as raw events
2235
Raw,
36+
37+
/// Write the ADΔER stream as raw events, but make sure that they are ordered perfectly according
38+
/// to their firing times
2339
RawInterleaved,
2440

41+
/// Do not write any data to the output stream
2542
#[default]
2643
Empty,
2744
}

adder-codec-core/src/lib.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub mod codec;
1111
mod codec_old;
1212
pub use bitstream_io;
1313
use bitstream_io::{BigEndian, BitReader};
14-
use std::cmp::{Ordering};
14+
use std::cmp::Ordering;
1515
use std::fs::File;
1616
use std::io::BufReader;
1717
use std::ops::Add;
@@ -33,7 +33,7 @@ pub enum PlaneError {
3333
}
3434

3535
#[allow(missing_docs)]
36-
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
36+
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq)]
3737
pub enum SourceCamera {
3838
#[default]
3939
FramedU8,
@@ -54,7 +54,7 @@ use crate::codec::compressed::blocks::{DeltaTResidual, EventResidual};
5454
use crate::codec::compressed::stream::CompressedInput;
5555
use crate::codec::decoder::Decoder;
5656
use crate::codec::raw::stream::RawInput;
57-
use crate::codec::{CodecError};
57+
use crate::codec::CodecError;
5858
use serde::{Deserialize, Serialize};
5959

6060
/// The type of time used in the ADΔER representation
@@ -154,6 +154,16 @@ impl PlaneSize {
154154
pub fn volume(&self) -> usize {
155155
self.area_wh() * self.channels as usize
156156
}
157+
158+
/// The smaller of the width and height dimensions
159+
pub fn min_resolution(&self) -> u16 {
160+
self.width.min(self.height)
161+
}
162+
163+
/// The larger of the width and height dimensions
164+
pub fn max_resolution(&self) -> u16 {
165+
self.width.max(self.height)
166+
}
157167
}
158168

159169
/// Decimation value; a pixel's sensitivity.
@@ -173,8 +183,13 @@ pub const D_ZERO_INTEGRATION: D = 254;
173183

174184
#[derive(Clone, Copy, PartialEq, Default)]
175185
pub enum Mode {
186+
/// Preserve temporal coherence for framed inputs. When an event fires, the ticks
187+
/// remaining for that input frame (and its associated intensity) are discarded. The
188+
/// difference in time is implied since the number of ticks per input frame is constant.
176189
#[default]
177190
FramePerfect,
191+
192+
/// Do not do the above ^
178193
Continuous,
179194
}
180195
/// Precision for maximum intensity representable with allowed [`D`] values
@@ -321,6 +336,8 @@ pub const D_START: D = 7;
321336
/// Number of ticks elapsed since a given pixel last fired an [`Event`]
322337
pub type DeltaT = u32;
323338

339+
/// Absolute firing time (in ticks) of an event. For a given pixel, this will always
340+
/// be grater than or equal to that of the pixel's last fired event.
324341
pub type AbsoluteT = u32;
325342

326343
/// Large count of ticks (e.g., for tracking the running timestamp of a sequence of [Events](Event)
@@ -570,7 +587,14 @@ pub struct EventCoordless {
570587
pub delta_t: DeltaT,
571588
}
572589

590+
impl Into<f64> for EventCoordless {
591+
fn into(self) -> f64 {
592+
panic!("Not implemented")
593+
}
594+
}
595+
573596
impl EventCoordless {
597+
/// Get the t or dt value
574598
#[inline(always)]
575599
pub fn t(&self) -> AbsoluteT {
576600
self.delta_t as AbsoluteT

adder-codec-rs/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ default-run = "adder_simulproc"
2020

2121
[features]
2222
default = ["transcoder"]
23-
transcoder = ["opencv", "dep:fast-math", "dep:adder-codec-core"]
23+
transcoder = ["opencv", "dep:fast-math", "adder-codec-core"]
2424
compression = ["opencv", "dep:fast-math", "adder-codec-core/compression"]
2525
raw-codec = []
26-
docs-only = ["opencv", "dep:fast-math", "dep:adder-codec-core"]
26+
docs-only = ["opencv", "dep:fast-math", "adder-codec-core"]
2727

2828

2929
[dependencies]

adder-codec-rs/examples/events_to_instantaneous_frames.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn main() {
4848
loop {
4949
match reader.digest_event(&mut bitreader) {
5050
Ok(mut event) => {
51-
if frame_sequence.ingest_event(&mut event) {
51+
if frame_sequence.ingest_event(&mut event, None) {
5252
match frame_sequence.write_multi_frame_bytes(&mut output_stream) {
5353
Ok(0) => {
5454
panic!("Should have frame, but didn't")

adder-codec-rs/src/bin/adder_simulproc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ mod tests {
174174
};
175175
let mut source = Framed::new(args.input_filename, args.color_input, args.scale)?
176176
// .chunk_rows(64)
177+
.crf(0)
178+
.time_parameters(5000 * 30, 5000, 120_000, Some(TimeMode::DeltaT))?
177179
.frame_start(args.frame_idx_start)?
178-
.c_thresh_pos(args.c_thresh_pos)
179180
.show_display(args.show_display);
180181

181182
let source_fps = source.source_fps;

adder-codec-rs/src/bin/adder_video_player.rs

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use adder_codec_core::codec::decoder::Decoder;
22
use adder_codec_core::codec::raw::stream::RawInput;
3-
use adder_codec_core::SourceCamera;
43
use adder_codec_core::D_ZERO_INTEGRATION;
4+
use adder_codec_core::{SourceCamera, TimeMode};
55
use adder_codec_rs::framer::scale_intensity::event_to_intensity;
66
use adder_codec_rs::transcoder::source::video::show_display_force;
77
use bitstream_io::{BigEndian, BitReader};
88
use clap::Parser;
9+
use ndarray::{Array, Array3};
910
use opencv::core::{create_continuous, Mat, MatTraitManual, CV_64F, CV_64FC3};
1011
use std::cmp::max;
1112
use std::error::Error;
@@ -72,6 +73,14 @@ fn main() -> Result<(), Box<dyn Error>> {
7273
let stdout = io::stdout();
7374
let mut handle = io::BufWriter::new(stdout.lock());
7475

76+
let mut last_timestamps = Array::zeros((
77+
stream.meta().plane.h_usize(),
78+
stream.meta().plane.w_usize(),
79+
stream.meta().plane.c_usize(),
80+
));
81+
82+
let time_mode = stream.meta().time_mode;
83+
7584
stream.set_input_stream_position(&mut bitreader, first_event_position)?;
7685

7786
let mut display_mat = Mat::default();
@@ -122,15 +131,55 @@ fn main() -> Result<(), Box<dyn Error>> {
122131
}
123132

124133
match stream.digest_event(&mut bitreader) {
125-
Ok(event) if event.d <= D_ZERO_INTEGRATION => {
134+
Ok(mut event) if event.d <= D_ZERO_INTEGRATION => {
126135
event_count += 1;
127136
let y = i32::from(event.coord.y);
128137
let x = i32::from(event.coord.x);
129138
let c = i32::from(event.coord.c.unwrap_or(0));
130-
if (y | x | c) == 0x0 {
131-
current_t += event.delta_t;
139+
140+
if time_mode == TimeMode::AbsoluteT {
141+
if event.delta_t > current_t {
142+
current_t = event.delta_t;
143+
}
144+
let dt = event.delta_t - last_timestamps[[y as usize, x as usize, c as usize]];
145+
last_timestamps[[y as usize, x as usize, c as usize]] = event.delta_t;
146+
if last_timestamps[[y as usize, x as usize, c as usize]]
147+
% stream.meta().ref_interval
148+
!= 0
149+
{
150+
last_timestamps[[y as usize, x as usize, c as usize]] = ((last_timestamps
151+
[[y as usize, x as usize, c as usize]]
152+
/ stream.meta().ref_interval)
153+
+ 1)
154+
* stream.meta().ref_interval;
155+
}
156+
event.delta_t = dt;
157+
} else {
158+
last_timestamps[[y as usize, x as usize, c as usize]] += event.delta_t;
159+
if last_timestamps[[y as usize, x as usize, c as usize]]
160+
% stream.meta().ref_interval
161+
!= 0
162+
{
163+
last_timestamps[[y as usize, x as usize, c as usize]] = ((last_timestamps
164+
[[y as usize, x as usize, c as usize]]
165+
/ stream.meta().ref_interval)
166+
+ 1)
167+
* stream.meta().ref_interval;
168+
}
169+
170+
if last_timestamps[[y as usize, x as usize, c as usize]] > current_t {
171+
current_t = last_timestamps[[y as usize, x as usize, c as usize]];
172+
}
132173
}
133174

175+
// else if (y | x | c) == 0x0 {
176+
// current_t += event.delta_t;
177+
// if stream.meta().source_camera == SourceCamera::FramedU8 {
178+
// current_t = ((current_t / stream.meta().ref_interval) + 1)
179+
// * stream.meta().ref_interval;
180+
// }
181+
// }
182+
134183
let frame_intensity = (event_to_intensity(&event) * f64::from(meta.ref_interval))
135184
/ match meta.source_camera {
136185
SourceCamera::FramedU8 => f64::from(u8::MAX),

0 commit comments

Comments
 (0)