Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

features detector checks for mask in a region #1772

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/aliceVision/featureEngine/FeatureExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ void FeatureExtractor::computeViewJob(const FeatureExtractorViewJob& job, bool u
double pixelRatio = 1.0;
job.view().getImage().getDoubleMetadata({"PixelAspectRatio"}, pixelRatio);

std::array<Vec2, 5> 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
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
}
}
}

Expand Down
Loading