Skip to content

Commit

Permalink
Merge pull request #1645 from alicevision/fix/fisheyeCircleFilter
Browse files Browse the repository at this point in the history
FeatureExtraction: Add analytical fisheye mask
  • Loading branch information
cbentejac authored Jan 15, 2024
2 parents 064ff12 + bd7cc6d commit 3a0be0f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/aliceVision/camera/Equidistant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class Equidistant : public IntrinsicScaleOffsetDisto

inline void setCircleCenterY(double y) { _circleCenter(1) = y; }

inline Vec2 getCircleCenter() const { return _circleCenter; }

/**
* @Brief get horizontal fov in radians
* @return horizontal fov in radians
Expand Down
38 changes: 36 additions & 2 deletions src/aliceVision/featureEngine/FeatureExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ void FeatureExtractor::computeViewJob(const FeatureExtractorViewJob& job, bool u
image::Image<unsigned char> imageGrayUChar;
image::Image<unsigned char> mask;



image::readImage(job.view().getImage().getImagePath(), imageGrayFloat, workingColorSpace);

double pixelRatio = 1.0;
Expand Down Expand Up @@ -234,7 +236,31 @@ void FeatureExtractor::computeViewJob(const FeatureExtractorViewJob& job, bool u
}
}

if (mask.height() > 0)
//Get Fisheye mask
bool isFisheye = false;
Vec2 circleCenter = Vec2::Zero();
double circleRadius = std::numeric_limits<double>::max();
auto & intrinsics = _sfmData.getIntrinsics();
if (job.view().getIntrinsicId() != UndefinedIndexT)
{
const auto & intrinsic = intrinsics.at(job.view().getIntrinsicId());
const auto & equidistant = std::dynamic_pointer_cast<const camera::Equidistant>(intrinsic);

//If the current view comes from a fisheye optic
if (equidistant)
{
//Make sure the circle radius has been initialized before
if (equidistant->getCircleRadius() > 1.0)
{
circleCenter = equidistant->getCircleCenter();
circleRadius = equidistant->getCircleRadius();
isFisheye = true;
}
}
}

//On mask or fisheye circle availability
if (mask.height() > 0 || isFisheye);
{
std::vector<feature::FeatureInImage> selectedIndices;
for (size_t i = 0, n = regions->RegionCount(); i != n; ++i)
Expand All @@ -243,8 +269,16 @@ void FeatureExtractor::computeViewJob(const FeatureExtractorViewJob& job, bool u
const int x = int(position.x());
const int y = int(position.y());


bool masked = false;
if (x < mask.width() && y < mask.height())

//Check if point lies inside potential fisheye circle
if ((position - circleCenter).norm() > circleRadius)
{
masked = true;
}
//Check if the optional image mask tells us to ignore this coordinate
else if (x < mask.width() && y < mask.height())
{
if ((mask(y, x) == 0 && !_maskInvert) || (mask(y, x) != 0 && _maskInvert))
{
Expand Down

0 comments on commit 3a0be0f

Please sign in to comment.