From 6f30513a73edabd126a594cc14f1f55c5c55a698 Mon Sep 17 00:00:00 2001 From: sladro Date: Wed, 1 Apr 2026 10:02:19 +0800 Subject: [PATCH] feat: add behavior event frame model --- include/behavior/behavior_event.h | 42 +++++++++++++++++++++++++++++ include/frame/frame.h | 10 +++---- include/frame/rect.h | 12 +++++++++ tests/CMakeLists.txt | 1 + tests/test_behavior_event_model.cpp | 33 +++++++++++++++++++++++ 5 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 include/behavior/behavior_event.h create mode 100644 include/frame/rect.h create mode 100644 tests/test_behavior_event_model.cpp diff --git a/include/behavior/behavior_event.h b/include/behavior/behavior_event.h new file mode 100644 index 0000000..4888b3e --- /dev/null +++ b/include/behavior/behavior_event.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include + +#include "frame/rect.h" + +namespace rk3588 { + +enum class BehaviorEventType { + Intrusion, + Climb, + Fall, + Fight +}; + +enum class BehaviorEventStatus { + Pending, + Active, + Ended +}; + +struct BehaviorEventItem { + int event_id = -1; + BehaviorEventType type = BehaviorEventType::Intrusion; + BehaviorEventStatus status = BehaviorEventStatus::Pending; + float score = 0.0f; + Rect bbox{}; + std::vector track_ids; + uint64_t start_pts = 0; + uint64_t last_pts = 0; + uint64_t duration_ms = 0; + std::string source; + std::string region_id; +}; + +struct BehaviorEventResult { + std::vector items; +}; + +} // namespace rk3588 diff --git a/include/frame/frame.h b/include/frame/frame.h index c928b86..fbafd70 100644 --- a/include/frame/frame.h +++ b/include/frame/frame.h @@ -8,7 +8,9 @@ #include #include +#include "behavior/behavior_event.h" #include "hw/frame_buffer.h" +#include "frame/rect.h" namespace rk3588 { @@ -23,13 +25,6 @@ enum class PixelFormat { UNKNOWN }; -struct Rect { - float x = 0.0f; - float y = 0.0f; - float w = 0.0f; - float h = 0.0f; -}; - struct Detection { int cls_id = -1; float score = 0.0f; @@ -86,6 +81,7 @@ struct Frame { std::shared_ptr buffer; std::shared_ptr det; + std::shared_ptr behavior_events; // Face recognition pipeline meta (kept separate from user_meta to avoid conflicts with publish). std::shared_ptr face_det; std::shared_ptr face_recog; diff --git a/include/frame/rect.h b/include/frame/rect.h new file mode 100644 index 0000000..4a60aa4 --- /dev/null +++ b/include/frame/rect.h @@ -0,0 +1,12 @@ +#pragma once + +namespace rk3588 { + +struct Rect { + float x = 0.0f; + float y = 0.0f; + float w = 0.0f; + float h = 0.0f; +}; + +} // namespace rk3588 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5c2835e..306127d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,6 +37,7 @@ add_executable(rk3588_gtests test_config_expand.cpp test_hw_factory.cpp test_frame_buffer.cpp + test_behavior_event_model.cpp test_infer_backend.cpp test_image_processor.cpp test_codec_backend.cpp diff --git a/tests/test_behavior_event_model.cpp b/tests/test_behavior_event_model.cpp new file mode 100644 index 0000000..610f318 --- /dev/null +++ b/tests/test_behavior_event_model.cpp @@ -0,0 +1,33 @@ +#include + +#include + +#include "frame/frame.h" + +namespace rk3588 { +namespace { + +TEST(BehaviorEventModelTest, FrameStoresBehaviorEventsSeparatelyFromDetections) { + auto frame = std::make_shared(); + frame->det = std::make_shared(); + frame->behavior_events = std::make_shared(); + + BehaviorEventItem item; + item.event_id = 7; + item.type = BehaviorEventType::Fall; + item.status = BehaviorEventStatus::Active; + item.track_ids = {42}; + item.duration_ms = 1600; + + frame->behavior_events->items.push_back(item); + + ASSERT_NE(frame->det, nullptr); + ASSERT_NE(frame->behavior_events, nullptr); + ASSERT_EQ(frame->behavior_events->items.size(), 1u); + ASSERT_EQ(frame->behavior_events->items[0].track_ids.size(), 1u); + EXPECT_EQ(frame->behavior_events->items[0].track_ids[0], 42); + EXPECT_EQ(frame->behavior_events->items[0].duration_ms, 1600u); +} + +} // namespace +} // namespace rk3588