#include #include #include #include #include "frame/frame.h" #include "../plugins/logic_gate/color_analyzer.h" namespace rk3588 { namespace { Frame MakeRgbFrame(int width, int height, uint8_t top_value, uint8_t middle_value, uint8_t bottom_value) { auto pixels = std::make_shared>(static_cast(width * height * 3), 0); for (int y = 0; y < height; ++y) { uint8_t value = bottom_value; if (y < (height * 35 / 100)) { value = top_value; } else if (y < (height * 75 / 100)) { value = middle_value; } for (int x = 0; x < width; ++x) { const size_t idx = static_cast((y * width + x) * 3); (*pixels)[idx] = value; (*pixels)[idx + 1] = value; (*pixels)[idx + 2] = value; } } Frame frame; frame.width = width; frame.height = height; frame.format = PixelFormat::RGB; frame.stride = width * 3; frame.data = pixels->data(); frame.data_size = pixels->size(); frame.data_owner = pixels; return frame; } TEST(ColorAnalyzerTest, UsesMiddleLowerRegionForBrightness) { ColorConfig config; config.method = ColorMethod::RGB; config.dark_threshold = 80; config.roi_expand = 1.0f; config.debug_output = false; ColorAnalyzer analyzer(config); Frame frame = MakeRgbFrame(10, 10, 180, 20, 200); Rect bbox{0.0f, 0.0f, 10.0f, 10.0f}; const ColorResult result = analyzer.Analyze(frame, bbox); ASSERT_TRUE(result.valid); EXPECT_TRUE(result.is_dark); EXPECT_LT(result.brightness, static_cast(config.dark_threshold)); EXPECT_GT(result.dark_ratio, result.light_ratio); EXPECT_GT(result.dark_ratio, result.mid_ratio); } TEST(ColorAnalyzerTest, ClassifiesLightDominatedSampleAsNonDark) { ColorConfig config; config.method = ColorMethod::RGB; config.dark_threshold = 80; config.roi_expand = 1.0f; config.debug_output = false; ColorAnalyzer analyzer(config); Frame frame = MakeRgbFrame(10, 10, 30, 210, 220); Rect bbox{0.0f, 0.0f, 10.0f, 10.0f}; const ColorResult result = analyzer.Analyze(frame, bbox); ASSERT_TRUE(result.valid); EXPECT_FALSE(result.is_dark); EXPECT_GT(result.light_ratio, result.dark_ratio); EXPECT_GT(result.light_ratio, result.mid_ratio); } } // namespace } // namespace rk3588