Skip to content

Commit e17a609

Browse files
authored
Merge pull request #1772 from alicevision/dev/featuresMasking
features detector checks for mask in a region
2 parents fa7e687 + 2f1066b commit e17a609

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/aliceVision/featureEngine/FeatureExtractor.cpp

+22-8
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ void FeatureExtractor::computeViewJob(const FeatureExtractorViewJob& job, bool u
172172
double pixelRatio = 1.0;
173173
job.view().getImage().getDoubleMetadata({"PixelAspectRatio"}, pixelRatio);
174174

175+
std::array<Vec2, 5> shifts;
176+
shifts[0] = Vec2(-1, 0);
177+
shifts[1] = Vec2(1, 0);
178+
shifts[2] = Vec2(0, -1);
179+
shifts[3] = Vec2(0, 1);
180+
shifts[4] = Vec2(0, 0);
181+
175182
if (pixelRatio != 1.0)
176183
{
177184
// Resample input image in order to work with square pixels
@@ -265,23 +272,30 @@ void FeatureExtractor::computeViewJob(const FeatureExtractorViewJob& job, bool u
265272
for (size_t i = 0, n = regions->RegionCount(); i != n; ++i)
266273
{
267274
const Vec2 position = regions->GetRegionPosition(i);
268-
const int x = int(position.x());
269-
const int y = int(position.y());
270-
271-
272275
bool masked = false;
273276

274277
//Check if point lies inside potential fisheye circle
275278
if ((position - circleCenter).norm() > circleRadius)
276279
{
277280
masked = true;
278281
}
279-
//Check if the optional image mask tells us to ignore this coordinate
280-
else if (x < mask.width() && y < mask.height())
282+
else
281283
{
282-
if ((mask(y, x) == 0 && !_maskInvert) || (mask(y, x) != 0 && _maskInvert))
284+
const double scale = regions->Features()[i].scale();
285+
//Check if the optional image mask tells us to ignore this coordinate
286+
for (int idx = 0; idx < shifts.size(); idx++)
283287
{
284-
masked = true;
288+
const Vec2 npos = position + scale * shifts[idx];
289+
const int x = int(npos.x());
290+
const int y = int(npos.y());
291+
292+
if (x >= 0 && y >= 0 && x < mask.width() && y < mask.height())
293+
{
294+
if ((mask(y, x) == 0 && !_maskInvert) || (mask(y, x) != 0 && _maskInvert))
295+
{
296+
masked = true;
297+
}
298+
}
285299
}
286300
}
287301

0 commit comments

Comments
 (0)