From f3d24974ee97a52e0f437eb5fa2605bcba3452d0 Mon Sep 17 00:00:00 2001 From: Fabien Servant Date: Tue, 29 Oct 2024 15:06:03 +0100 Subject: [PATCH] check for mask in a region instead of a single point --- .../featureEngine/FeatureExtractor.cpp | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/aliceVision/featureEngine/FeatureExtractor.cpp b/src/aliceVision/featureEngine/FeatureExtractor.cpp index 4f046de65e..efbbf5a97c 100644 --- a/src/aliceVision/featureEngine/FeatureExtractor.cpp +++ b/src/aliceVision/featureEngine/FeatureExtractor.cpp @@ -172,6 +172,13 @@ void FeatureExtractor::computeViewJob(const FeatureExtractorViewJob& job, bool u double pixelRatio = 1.0; job.view().getImage().getDoubleMetadata({"PixelAspectRatio"}, pixelRatio); + std::array shifts; + shifts[0] = Vec2(-1, 0); + shifts[1] = Vec2(1, 0); + shifts[2] = Vec2(0, -1); + shifts[3] = Vec2(0, 1); + shifts[4] = Vec2(0, 0); + if (pixelRatio != 1.0) { // Resample input image in order to work with square pixels @@ -265,9 +272,8 @@ void FeatureExtractor::computeViewJob(const FeatureExtractorViewJob& job, bool u for (size_t i = 0, n = regions->RegionCount(); i != n; ++i) { const Vec2 position = regions->GetRegionPosition(i); - const int x = int(position.x()); - const int y = int(position.y()); - + + bool masked = false; @@ -276,12 +282,23 @@ void FeatureExtractor::computeViewJob(const FeatureExtractorViewJob& job, bool u { masked = true; } - //Check if the optional image mask tells us to ignore this coordinate - else if (x < mask.width() && y < mask.height()) + else { - if ((mask(y, x) == 0 && !_maskInvert) || (mask(y, x) != 0 && _maskInvert)) + //Check if the optional image mask tells us to ignore this coordinate + for (int idx = 0; idx < shifts.size(); idx++) { - masked = true; + const double scale = regions->Features()[i].scale(); + const Vec2 npos = position + scale * shifts[idx]; + const int x = int(npos.x()); + const int y = int(npos.y()); + + if (x >= 0 && y >= 0 && x < mask.width() && y < mask.height()) + { + if ((mask(y, x) == 0 && !_maskInvert) || (mask(y, x) != 0 && _maskInvert)) + { + masked = true; + } + } } }