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

[matching] build fix for MSVC 2019 #805

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
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
46 changes: 41 additions & 5 deletions src/aliceVision/matching/kvld/algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include "algorithm.h"

#include <boost/math/constants/constants.hpp>

IntegralImages::IntegralImages(const aliceVision::image::Image< float >& I)
{
map.resize( I.Width() + 1, I.Height() + 1 );
Expand All @@ -26,12 +28,9 @@ IntegralImages::IntegralImages(const aliceVision::image::Image< float >& I)
}
}

float getRange(
const aliceVision::image::Image< float >& I,
int a,
const float p )
float getRange( const aliceVision::image::Image< float >& I, int a, const float p )
{
float range = sqrt( float( 3.f * I.Height() * I.Width() ) / ( p * a * PI_ ) );
float range = sqrt(float(3.f * I.Height() * I.Width()) / (p * a * boost::math::constants::pi<float>()));
return range;
}

Expand All @@ -55,3 +54,40 @@ std::ifstream& readDetector( std::ifstream& in, aliceVision::feature::PointFeatu
>> point.orientation();
return in;
}

bool anglefrom( float x, float y, float& angle )
{
using namespace boost::math;

if(x != 0)
angle = std::atan(y / x);
else if(y > 0)
angle = constants::pi<float>() / 2;
else if(y < 0)
angle = -constants::pi<float>() / 2;
else
return false;

if(x < 0)
angle += constants::pi<float>();
while(angle < 0)
angle += 2 * constants::pi<float>();
while(angle >= 2 * constants::pi<float>())
angle -= 2 * constants::pi<float>();
assert(angle >= 0 && angle < 2 * constants::pi<float>());
return true;
}

double angle_difference( double angle1, double angle2 )
{
using namespace boost::math;

double angle = angle1 - angle2;
while(angle < 0)
angle += 2 * constants::pi<double>();
while(angle >= 2 * constants::pi<double>())
angle -= 2 * constants::pi<double>();

assert(angle <= 2 * constants::pi<double>() && angle >= 0);
return std::min(angle, 2 * constants::pi<double>() - angle);
}
31 changes: 2 additions & 29 deletions src/aliceVision/matching/kvld/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <functional>


const float PI_ = 4.0 * atan( 1.0f );

//============================== simplified structure of a point=============================//
//if you set KVLD geometry verification to false, you only need to fill x and y in a point structure
Expand Down Expand Up @@ -108,35 +107,9 @@ inline bool inside( int w, int h, int x,int y, double radius )
return( x - radius >= 0 && y - radius >= 0 && x + radius < w && y + radius < h );
}

inline bool anglefrom( const float& x, const float& y, float& angle )
{
if( x != 0 )
angle = atan( y / x );
else if( y > 0 )
angle = PI_ / 2;
else if( y < 0 )
angle =- PI_ / 2;
else return false;

if( x < 0 )
angle += PI_;
while( angle < 0 )
angle += 2 * PI_;
while( angle >= 2 * PI_ )
angle -= 2 * PI_;
assert( angle >= 0 && angle < 2 * PI_ );
return true;
}
bool anglefrom(float x, float y, float& angle);

inline double angle_difference( const double angle1, const double angle2 )
{
double angle = angle1 - angle2;
while( angle < 0 ) angle += 2 * PI_;
while( angle >= 2 * PI_ ) angle -= 2 * PI_;

assert(angle <= 2 * PI_ && angle >= 0 );
return std::min( angle, 2 * PI_ - angle );
}
double angle_difference(double angle1, double angle2);

inline void max( double* list,double& weight, int size, int& index, int& second_index )
{
Expand Down
20 changes: 15 additions & 5 deletions src/aliceVision/matching/kvld/kvld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ int ImageScale::getIndex( const double r )const
template< typename T >
VLD::VLD( const ImageScale& series, T const& P1, T const& P2 ) : contrast( 0.0 )
{
using namespace boost::math;

//============== initializing============//
principleAngle.fill( 0 );
descriptor.fill( 0 );
Expand Down Expand Up @@ -161,12 +163,12 @@ VLD::VLD( const ImageScale& series, T const& P1, T const& P2 ) : contrast( 0.0 )

//cout<<angle<<endl;
while( angle < 0 )
angle += 2 * PI_;
while( angle >= 2 * PI_)
angle -= 2 * PI_;
angle += 2 * constants::pi<double>();
while(angle >= 2 * constants::pi<double>())
angle -= 2 * constants::pi<double>();

//===============principle angle==============================//
const int index = int( angle * binNum / ( 2 * PI_ ) + 0.5 );
const int index = int(angle * binNum / (2 * constants::pi<double>()) + 0.5);

double Gweight = exp( -d * d / 4.5 / sigma2 ) * ( m( y, x ) );
if( index < binNum )
Expand All @@ -175,7 +177,7 @@ VLD::VLD( const ImageScale& series, T const& P1, T const& P2 ) : contrast( 0.0 )
statistic[ 0 ] += Gweight;

//==============the descriptor===============================//
const int index2 = int( angle * subdirection / ( 2 * PI_ ) + 0.5 );
const int index2 = int(angle * subdirection / (2 * constants::pi<double>()) + 0.5);
assert( index2 >= 0 && index2 <= subdirection );

if( index2 < subdirection )
Expand Down Expand Up @@ -431,3 +433,11 @@ float KVLD( const Image< float >& I1,
return float( matchesFiltered.size() ) / matches.size();
}

double VLD::get_orientation() const
{
const float dy = end_point[1] - begin_point[1];
const float dx = end_point[0] - begin_point[0];
float angle;
anglefrom(dx, dy, angle);
return angle;
}
10 changes: 2 additions & 8 deletions src/aliceVision/matching/kvld/kvld.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,8 @@ class VLD
template< typename T >
VLD( const ImageScale& series, T const& P1, T const& P2 );
//=========================================class functions==============================================//
inline double get_orientation()const
{
float dy = end_point[ 1 ] - begin_point[ 1 ];
float dx = end_point[ 0 ] - begin_point[ 0 ];
float angle;
anglefrom( dx, dy, angle );
return angle;
}
double get_orientation() const;

inline double difference( const VLD& vld2 )const
{
double diff[ 2 ];
Expand Down