Skip to content

Commit 15fe452

Browse files
author
umgnunes
committed
Add spatial crop utility
1 parent 73f51d3 commit 15fe452

File tree

5 files changed

+87
-11
lines changed

5 files changed

+87
-11
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ FetchContent_Declare(
5151
)
5252
FetchContent_MakeAvailable(sepia)
5353

54+
# tarsier
55+
FetchContent_Declare(
56+
tarsier
57+
GIT_REPOSITORY https://github.com/neuromorphic-paris/tarsier
58+
GIT_TAG master
59+
)
60+
FetchContent_MakeAvailable(tarsier)
61+
5462
# Source
5563
add_subdirectory(${${LIB_NAME}_SOURCE_DIR})
5664

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ The following are dependencies that are automatically downloaded during the buil
3838

3939
- sepia: <https://github.com/neuromorphic-paris/sepia>
4040

41+
- tarsier: <https://github.com/neuromorphic-paris/tarsier>
42+
4143
- googletest (only downloaded if tests are enabled): <https://github.com/google/googletest.git>
4244

4345
### General

src/batch_size.cpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "event_batch.hpp"
44
#include "pontella.hpp"
5+
#include "select_rectangle.hpp"
56
#include "sepia.hpp"
67

78
int
@@ -16,6 +17,10 @@ main(int argc, char* argv[])
1617
{
1718
uint64_t t_decay_first;
1819
float weight_thresh;
20+
uint16_t left;
21+
uint16_t right;
22+
uint16_t bottom;
23+
uint16_t top;
1924
};
2025

2126
return pontella::main(
@@ -26,16 +31,40 @@ main(int argc, char* argv[])
2631
" defaults to 10000",
2732
" -e e, --weight-threshold e sets the weight threshold",
2833
" defaults to 0.1",
34+
" -cl cl, --crop-left cl sets the crop's left side "
35+
"coordinate",
36+
" defaults to 0",
37+
" -cr cr, --crop-right cr sets the crop's right side "
38+
"coordinate",
39+
" defaults to context width",
40+
" -cb cb, --crop-bottom cb sets the crop's bottom side "
41+
"coordinate",
42+
" defaults to 0",
43+
" -ct ct, --crop-top ct sets the crop's top side "
44+
"coordinate",
45+
" defaults to context height",
2946
" -h, --help shows this help message"},
30-
argc, argv, 1, {{"time-decay-first", {"t"}}, {"weight-threshold", {"e"}}},
47+
argc, argv, 1,
48+
{{"time-decay-first", {"t"}},
49+
{"weight-threshold", {"e"}},
50+
{"crop-left", {"cl"}},
51+
{"crop-right", {"cr"}},
52+
{"crop-bottom", {"cb"}},
53+
{"crop-top", {"ct"}}},
3154
{}, [&](pontella::command command) {
3255
const std::string& filename = command.arguments[0];
56+
const auto header =
57+
sepia::read_header(sepia::filename_to_ifstream(filename));
3358

3459
Arguments arguments;
3560
arguments.t_decay_first =
3661
extract_argument(command, "time-decay-first", 10000);
3762
arguments.weight_thresh =
3863
extract_argument(command, "weight-threshold", 0.1);
64+
arguments.left = extract_argument(command, "crop-left", 0);
65+
arguments.right = extract_argument(command, "crop-right", header.width);
66+
arguments.bottom = extract_argument(command, "crop-bottom", 0);
67+
arguments.top = extract_argument(command, "crop-top", header.height);
3968

4069
Decay event_decay;
4170
auto handle_global_decay = [&](Decay decay) { event_decay = decay; };
@@ -55,11 +84,15 @@ main(int argc, char* argv[])
5584
auto batch = make_batch<Event>(arguments.weight_thresh, event_decay,
5685
handle_batch);
5786

87+
auto crop = tarsier::make_select_rectangle<Event>(
88+
arguments.left, arguments.bottom, arguments.right - arguments.left,
89+
arguments.top - arguments.bottom, [&](Event event) {
90+
global_decay(event);
91+
batch(event);
92+
});
93+
5894
sepia::join_observable<Type>(sepia::filename_to_ifstream(filename),
59-
[&](Event event) {
60-
global_decay(event);
61-
batch(event);
62-
});
95+
crop);
6396

6497
if (batch.batch().size() > 0)
6598
{

src/batch_timestamp.cpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "event_batch.hpp"
44
#include "pontella.hpp"
5+
#include "select_rectangle.hpp"
56
#include "sepia.hpp"
67

78
int
@@ -16,6 +17,10 @@ main(int argc, char* argv[])
1617
{
1718
uint64_t t_decay_first;
1819
float weight_thresh;
20+
uint16_t left;
21+
uint16_t right;
22+
uint16_t bottom;
23+
uint16_t top;
1924
};
2025

2126
return pontella::main(
@@ -27,16 +32,40 @@ main(int argc, char* argv[])
2732
" defaults to 10000",
2833
" -e e, --weight-threshold e sets the weight threshold",
2934
" defaults to 0.1",
35+
" -cl cl, --crop-left cl sets the crop's left side "
36+
"coordinate",
37+
" defaults to 0",
38+
" -cr cr, --crop-right cr sets the crop's right side "
39+
"coordinate",
40+
" defaults to context width",
41+
" -cb cb, --crop-bottom cb sets the crop's bottom side "
42+
"coordinate",
43+
" defaults to 0",
44+
" -ct ct, --crop-top ct sets the crop's top side "
45+
"coordinate",
46+
" defaults to context height",
3047
" -h, --help shows this help message"},
31-
argc, argv, 1, {{"time-decay-first", {"t"}}, {"weight-threshold", {"e"}}},
48+
argc, argv, 1,
49+
{{"time-decay-first", {"t"}},
50+
{"weight-threshold", {"e"}},
51+
{"crop-left", {"cl"}},
52+
{"crop-right", {"cr"}},
53+
{"crop-bottom", {"cb"}},
54+
{"crop-top", {"ct"}}},
3255
{}, [&](pontella::command command) {
3356
const std::string& filename = command.arguments[0];
57+
const auto header =
58+
sepia::read_header(sepia::filename_to_ifstream(filename));
3459

3560
Arguments arguments;
3661
arguments.t_decay_first =
3762
extract_argument(command, "time-decay-first", 10000);
3863
arguments.weight_thresh =
3964
extract_argument(command, "weight-threshold", 0.1);
65+
arguments.left = extract_argument(command, "crop-left", 0);
66+
arguments.right = extract_argument(command, "crop-right", header.width);
67+
arguments.bottom = extract_argument(command, "crop-bottom", 0);
68+
arguments.top = extract_argument(command, "crop-top", header.height);
4069

4170
Decay event_decay;
4271
auto handle_global_decay = [&](Decay decay) { event_decay = decay; };
@@ -56,11 +85,15 @@ main(int argc, char* argv[])
5685
auto batch = make_batch<Event>(arguments.weight_thresh, event_decay,
5786
handle_batch);
5887

88+
auto crop = tarsier::make_select_rectangle<Event>(
89+
arguments.left, arguments.bottom, arguments.right - arguments.left,
90+
arguments.top - arguments.bottom, [&](Event event) {
91+
global_decay(event);
92+
batch(event);
93+
});
94+
5995
sepia::join_observable<Type>(sepia::filename_to_ifstream(filename),
60-
[&](Event event) {
61-
global_decay(event);
62-
batch(event);
63-
});
96+
crop);
6497

6598
if (batch.batch().size() > 0)
6699
{

src/event_batch/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
add_library(${LIB_NAME} INTERFACE)
33

44
target_include_directories(${LIB_NAME} INTERFACE ${${LIB_NAME}_INCLUDE_DIR}
5-
${pontella_SOURCE_DIR}/source ${sepia_SOURCE_DIR}/source)
5+
${pontella_SOURCE_DIR}/source ${sepia_SOURCE_DIR}/source ${tarsier_SOURCE_DIR}/source)
66
target_link_libraries(${LIB_NAME} INTERFACE pthread)

0 commit comments

Comments
 (0)