Adjust shoe color sampling window

This commit is contained in:
tian 2026-04-14 17:47:45 +08:00
parent 866ab2c27c
commit f1f0922edf
2 changed files with 16 additions and 9 deletions

View File

@ -33,10 +33,12 @@ ColorResult ColorAnalyzer::Analyze(const Frame& frame, const Rect& bbox) {
return result;
}
const int sample_w = crop_w;
const int sample_h = std::max(1, crop_h / 3);
const int sample_x = 0;
const int sample_y = std::max(0, crop_h - sample_h);
// Sample the middle-lower shoe surface to avoid both bright trouser fabric
// above and reflective floor pixels near the sole.
const int sample_w = std::max(1, static_cast<int>(crop_w * 0.6f));
const int sample_h = std::max(1, static_cast<int>(crop_h * 0.4f));
const int sample_x = std::max(0, (crop_w - sample_w) / 2);
const int sample_y = std::max(0, static_cast<int>(crop_h * 0.35f));
std::vector<uint8_t> sample(sample_w * sample_h * 3);
for (int row = 0; row < sample_h; ++row) {

View File

@ -10,10 +10,15 @@
namespace rk3588 {
namespace {
Frame MakeRgbFrame(int width, int height, uint8_t top_value, uint8_t bottom_value) {
Frame MakeRgbFrame(int width, int height, uint8_t top_value, uint8_t middle_value, uint8_t bottom_value) {
auto pixels = std::make_shared<std::vector<uint8_t>>(static_cast<size_t>(width * height * 3), 0);
for (int y = 0; y < height; ++y) {
const uint8_t value = (y < (height * 2 / 3)) ? top_value : bottom_value;
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<size_t>((y * width + x) * 3);
(*pixels)[idx] = value;
@ -33,7 +38,7 @@ Frame MakeRgbFrame(int width, int height, uint8_t top_value, uint8_t bottom_valu
return frame;
}
TEST(ColorAnalyzerTest, UsesBottomThirdInsteadOfCenterRegionForBrightness) {
TEST(ColorAnalyzerTest, UsesMiddleLowerRegionForBrightness) {
ColorConfig config;
config.method = ColorMethod::RGB;
config.dark_threshold = 80;
@ -41,8 +46,8 @@ TEST(ColorAnalyzerTest, UsesBottomThirdInsteadOfCenterRegionForBrightness) {
config.debug_output = false;
ColorAnalyzer analyzer(config);
Frame frame = MakeRgbFrame(9, 9, 180, 20);
Rect bbox{0.0f, 0.0f, 9.0f, 9.0f};
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);