Skip to content

Commit

Permalink
Fix some style issues and some code improvement detected by codacy op…
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoulon committed Jul 4, 2017
1 parent 6fb4683 commit a968c43
Show file tree
Hide file tree
Showing 180 changed files with 2,347 additions and 2,390 deletions.
9 changes: 5 additions & 4 deletions src/openMVG/cameras/Camera_Pinhole_Radial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ class Pinhole_Intrinsic_Radial_K1 : public Pinhole_Intrinsic
int w = 0, int h = 0,
double focal = 0.0, double ppx = 0, double ppy = 0,
double k1 = 0.0 )
: Pinhole_Intrinsic( w, h, focal, ppx, ppy )
: Pinhole_Intrinsic( w, h, focal, ppx, ppy ),
params_({k1})
{
params_ = {k1};

}

~Pinhole_Intrinsic_Radial_K1() override = default;
Expand Down Expand Up @@ -309,9 +310,9 @@ class Pinhole_Intrinsic_Radial_K3 : public Pinhole_Intrinsic
int w = 0, int h = 0,
double focal = 0.0, double ppx = 0, double ppy = 0,
double k1 = 0.0, double k2 = 0.0, double k3 = 0.0 )
: Pinhole_Intrinsic( w, h, focal, ppx, ppy )
: Pinhole_Intrinsic( w, h, focal, ppx, ppy ),
params_({k1, k2, k3})
{
params_ = {k1, k2, k3};
}

~Pinhole_Intrinsic_Radial_K3() override = default;
Expand Down
19 changes: 9 additions & 10 deletions src/openMVG/cameras/Camera_undistort_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ void UndistortImage(
* @param cam Input intrinsic parameter used to undistort image
* @param[out] image_ud Output undistorted image
* @param fillcolor color used to fill pixels where no input pixel is found
* @param max_ud_width Maximum width of the undistorted image
* @param max_ud_height Maximum height of the undistorted image
* @param max_ud_width Maximum width of the undistorted image
* @param max_ud_height Maximum height of the undistorted image
* @note This function produces an image with size that try to fit the image plane
*/
template <typename Image>
Expand All @@ -92,9 +92,9 @@ void UndistortImageResized(
int max_x = std::numeric_limits<int>::lowest();
int max_y = std::numeric_limits<int>::lowest();

for( int id_row = 0 ; id_row < imageIn.Height() ; ++id_row )
for (int id_row = 0; id_row < imageIn.Height(); ++id_row )
{
for( int id_col = 0 ; id_col < imageIn.Width() ; ++id_col )
for (int id_col = 0; id_col < imageIn.Width(); ++id_col )
{
const Vec2 dist_pix( id_col , id_row );
const Vec2 undist_pix = cam->get_ud_pixel( dist_pix );
Expand All @@ -116,17 +116,17 @@ void UndistortImageResized(
// Compute real size (ensure we do not have infinite size)
const uint32_t real_size_x = std::min( max_ud_width , (uint32_t)computed_size_x );
const uint32_t real_size_y = std::min( max_ud_height , (uint32_t)computed_size_y );
// 2 - Compute inverse projection to fill the output image

// 2 - Compute inverse projection to fill the output image
image_ud.resize( real_size_x , real_size_y , true, fillcolor );
const image::Sampler2d<image::SamplerLinear> sampler;

#ifdef OPENMVG_USE_OPENMP
#pragma omp parallel for
#endif
for ( int j = 0; j < real_size_y; ++j )
for ( int i = 0; i < real_size_x ; ++i )
{
for ( int i = 0; i < real_size_x; ++i )
{
const Vec2 undisto_pix( i + min_x , j + min_y );
// compute coordinates with distortion
const Vec2 disto_pix = cam->get_d_pixel( undisto_pix );
Expand All @@ -149,4 +149,3 @@ void UndistortImageResized(
} // namespace openMVG

#endif // #ifndef OPENMVG_CAMERAS_CAMERA_UNDISTORT_IMAGE_HPP

4 changes: 2 additions & 2 deletions src/openMVG/cameras/PinholeCamera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ struct PinholeCamera
P_From_KRt(_K, _R, _t, &_P);
}

PinholeCamera(const Mat34 & P)
explicit PinholeCamera(const Mat34 & P)
: _P(P)
{
_P = P;
KRt_From_P(_P, &_K, &_R, &_t);
_C = -_R.transpose() * _t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void normalizeHisto(const std::vector<T> & vec_df, std::vector<double> &
{
double totalCount = static_cast<double>(std::accumulate(vec_df.begin(), vec_df.end(), 0));
vec_normalized_df.resize(vec_df.size(), 0.0);
for(size_t i=0; i<vec_df.size(); i++)
for (size_t i=0; i<vec_df.size(); i++)
vec_normalized_df[i] = vec_df[i] / totalCount;
}

Expand All @@ -63,7 +63,7 @@ template<typename T>
static void cdf(const std::vector<T> & vec_df, std::vector<T> & vec_cdf)
{
vec_cdf = vec_df;
for(size_t i=1; i<vec_cdf.size(); i++)
for (size_t i=1; i<vec_cdf.size(); i++)
vec_cdf[i] = vec_cdf[i] + vec_cdf[i-1];
}

Expand Down Expand Up @@ -163,7 +163,7 @@ static void Encode_histo_relation(

std::vector<double>::const_iterator cdf_I_IterBegin = cdf_I.begin();
std::vector<double>::const_iterator cdf_J_IterBegin = cdf_J.begin();
while( currentPourcentile < 1.0)
while (currentPourcentile < 1.0)
{
std::vector<double>::const_iterator iterFI = std::lower_bound(cdf_I.begin(), cdf_I.end(), currentPourcentile);
const size_t positionI = std::distance(cdf_I_IterBegin, iterFI);
Expand All @@ -181,7 +181,7 @@ static void Encode_histo_relation(
// pos * ga + offa - pos * gb - offb <= gamma
// pos * ga + offa - pos * gb - offb >= - gamma

for(size_t k = 0; k < vec_pourcentilePositionI.size(); ++k)
for (size_t k = 0; k < vec_pourcentilePositionI.size(); ++k)
{
A.coeffRef(rowPos, GVAR(edge.I)) = vec_pourcentilePositionI[k];
A.coeffRef(rowPos, OFFSETVAR(edge.I)) = 1.0;
Expand Down
4 changes: 2 additions & 2 deletions src/openMVG/color_harmonization/selection_VLDSegment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class commonDataByPair_VLDSegment : public commonDataByPair

std::vector< Pair > matchesFiltered, matchesPair;

for( std::vector< matching::IndMatch >::const_iterator iter_match = _vec_PutativeMatches.begin();
for (std::vector< matching::IndMatch >::const_iterator iter_match = _vec_PutativeMatches.begin();
iter_match != _vec_PutativeMatches.end();
++iter_match )
{
Expand Down Expand Up @@ -90,7 +90,7 @@ class commonDataByPair_VLDSegment : public commonDataByPair
}

bool bOk = false;
if( !matchesPair.empty())
if (!matchesPair.empty())
{
// Get mask
getKVLDMask(
Expand Down
8 changes: 4 additions & 4 deletions src/openMVG/color_harmonization/selection_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class commonDataByPair
* \param[out] maskLeft Mask of the left image (initialized to corresponding image size).
* \param[out] maskRight Mask of the right image (initialized to corresponding image size).
*
* \return True if(mask not empty).
* \return True if (mask not empty).
*/
virtual bool computeMask( image::Image< unsigned char > & maskLeft, image::Image< unsigned char > & maskRight ) = 0;

Expand All @@ -53,11 +53,11 @@ class commonDataByPair
size_t channelIndex,
const image::Image< ImageType >& image )
{
for( int j = 0; j < mask.Height(); ++j )
for (int j = 0; j < mask.Height(); ++j )
{
for( int i = 0; i < mask.Width(); ++i )
for (int i = 0; i < mask.Width(); ++i )
{
if( ( int )mask( j, i ) != 0 )
if (( int )mask( j, i ) != 0 )
{
histo.Add( image( j, i )( channelIndex ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class commonDataByPair_MatchedPoints : public commonDataByPair
{
maskLeft.fill(0);
maskRight.fill(0);
for( std::vector< matching::IndMatch >::const_iterator
for (std::vector< matching::IndMatch >::const_iterator
iter_putativeMatches = _vec_PutativeMatches.begin();
iter_putativeMatches != _vec_PutativeMatches.end();
++iter_putativeMatches )
Expand Down
4 changes: 3 additions & 1 deletion src/openMVG/exif/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
add_definitions(-DTHIS_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")

UNIT_TEST(openMVG exif_IO "stlplus;easyexif")
target_compile_definitions(openMVG_test_exif_IO
PRIVATE -DTHIS_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")

add_subdirectory(sensor_width_database)
4 changes: 2 additions & 2 deletions src/openMVG/exif/exif_IO_EasyExif.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace exif
*/
inline std::string trim_copy( const std::string& s )
{
if( s.empty() )
if (s.empty() )
{
return s;
}
Expand Down Expand Up @@ -61,7 +61,7 @@ class Exif_IO_EasyExif : public Exif_IO
* @brief Constructor using a file
* @param sFileName path of the image to analyze
*/
Exif_IO_EasyExif( const std::string & sFileName ): bHaveExifInfo_( false )
explicit Exif_IO_EasyExif( const std::string & sFileName ): bHaveExifInfo_( false )
{
open( sFileName );
}
Expand Down
5 changes: 2 additions & 3 deletions src/openMVG/exif/sensor_width_database/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@


ADD_DEFINITIONS(-DTHIS_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")

UNIT_TEST(openMVG ParseDatabase "stlplus")
target_compile_definitions(openMVG_test_ParseDatabase
PRIVATE -DTHIS_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")

# Installation rules
install(FILES sensor_width_camera_database.txt DESTINATION share/openMVG)
58 changes: 29 additions & 29 deletions src/openMVG/features/akaze/AKAZE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ using namespace openMVG::image;

/// Lookup table for 2d gaussian (sigma = 2.5) where (0,0) is top left and (6,6) is bottom right
const float gauss25[7][7] = {
{0.02546481f, 0.02350698f, 0.01849125f, 0.01239505f, 0.00708017f, 0.00344629f, 0.00142946f},
{0.02350698f, 0.02169968f, 0.01706957f, 0.01144208f, 0.00653582f, 0.00318132f, 0.00131956f},
{0.01849125f, 0.01706957f, 0.01342740f, 0.00900066f, 0.00514126f, 0.00250252f, 0.00103800f},
{0.01239505f, 0.01144208f, 0.00900066f, 0.00603332f, 0.00344629f, 0.00167749f, 0.00069579f},
{0.00708017f, 0.00653582f, 0.00514126f, 0.00344629f, 0.00196855f, 0.00095820f, 0.00039744f},
{0.00344629f, 0.00318132f, 0.00250252f, 0.00167749f, 0.00095820f, 0.00046640f, 0.00019346f},
{0.00142946f, 0.00131956f, 0.00103800f, 0.00069579f, 0.00039744f, 0.00019346f, 0.00008024f}
{0.02546481f, 0.02350698f, 0.01849125f, 0.01239505f, 0.00708017f, 0.00344629f, 0.00142946f},
{0.02350698f, 0.02169968f, 0.01706957f, 0.01144208f, 0.00653582f, 0.00318132f, 0.00131956f},
{0.01849125f, 0.01706957f, 0.01342740f, 0.00900066f, 0.00514126f, 0.00250252f, 0.00103800f},
{0.01239505f, 0.01144208f, 0.00900066f, 0.00603332f, 0.00344629f, 0.00167749f, 0.00069579f},
{0.00708017f, 0.00653582f, 0.00514126f, 0.00344629f, 0.00196855f, 0.00095820f, 0.00039744f},
{0.00344629f, 0.00318132f, 0.00250252f, 0.00167749f, 0.00095820f, 0.00046640f, 0.00019346f},
{0.00142946f, 0.00131956f, 0.00103800f, 0.00069579f, 0.00039744f, 0.00019346f, 0.00008024f}
};

// Compute slice scale
static inline float Sigma( const float sigma0 , const int p , const int q , const int Q )
{
if( p == 0 && q == 0 )
if (p == 0 && q == 0 )
return sigma0;
else
return sigma0 * powf( 2.f , p + static_cast<float>( q ) / static_cast<float>( Q ) );
Expand Down Expand Up @@ -64,18 +64,18 @@ float AKAZE::ComputeAutomaticContrastFactor( const Image<float> & src , const fl

int nb_value = 0;

for( int i = 1; i < height - 1; ++i )
for (int i = 1; i < height - 1; ++i )
{
for( int j = 1; j < width - 1; ++j )
for (int j = 1; j < width - 1; ++j )
{
const float val = grad( i , j );

if( val > 0 )
if (val > 0 )
{
int bin_id = floor( (val / grad_max ) * static_cast<float>(nb_bin) );

// Handle overflow (need to do it in a cleaner way)
if( bin_id == nb_bin )
if (bin_id == nb_bin )
--bin_id;

// Accumulate
Expand All @@ -89,14 +89,14 @@ float AKAZE::ComputeAutomaticContrastFactor( const Image<float> & src , const fl

size_t id_bin = 0;
size_t acc = 0;
while( acc < search_id && id_bin < nb_bin )
while (acc < search_id && id_bin < nb_bin)
{
acc += histo[ id_bin ];
++id_bin;
}

// Handle 0 bin search
if( acc < search_id )
if (acc < search_id )
{
return 0.03f; // Only empiric value
}
Expand All @@ -121,7 +121,7 @@ void AKAZE::ComputeAKAZESlice( const Image<float> & src , const int p , const in
const int sigma_scale = std::round(sigma_cur * fderivative_factor / ratio);

Image<float> smoothed;
if( p == 0 && q == 0 )
if (p == 0 && q == 0 )
{
// Compute new image
ImageGaussianFilter( src , sigma0 , Li, 0, 0);
Expand All @@ -130,7 +130,7 @@ void AKAZE::ComputeAKAZESlice( const Image<float> & src , const int p , const in
{
// general case
Image<float> in;
if( q == 0 ) {
if (q == 0 ) {
ImageHalfSample( src , in );
}
else {
Expand Down Expand Up @@ -162,7 +162,7 @@ void AKAZE::ComputeAKAZESlice( const Image<float> & src , const int p , const in
}

// Compute Hessian response
if( p == 0 && q == 0 )
if (p == 0 && q == 0 )
{
smoothed = Li;
}
Expand Down Expand Up @@ -220,11 +220,11 @@ void AKAZE::Compute_AKAZEScaleSpace()
Image<float> input = in_;

// Octave computation
for( int p = 0; p < options_.iNbOctave; ++p )
for (int p = 0; p < options_.iNbOctave; ++p )
{
contrast_factor *= (p == 0) ? 1.f : 0.75f;

for( int q = 0; q < options_.iNbSlicePerOctave; ++q )
for (int q = 0; q < options_.iNbSlicePerOctave; ++q )
{
evolution_.emplace_back(TEvolution());
TEvolution & evo = evolution_.back();
Expand Down Expand Up @@ -253,20 +253,20 @@ void detectDuplicates(
std::vector<std::pair<AKAZEKeypoint, bool> > & current)
{
// mark duplicates - using a full search algorithm
for(std::vector<std::pair<AKAZEKeypoint, bool> >::iterator p1=previous.begin(); p1<previous.end(); ++p1)
for (std::pair<AKAZEKeypoint, bool> & p1 : previous)
{
for(std::vector<std::pair<AKAZEKeypoint, bool> >::iterator p2 = current.begin(); p2<current.end(); ++p2)
for (std::pair<AKAZEKeypoint, bool> & p2 : current)
{
if (p2->second == true) continue;
if (p2.second == true) continue;

// Check spatial distance
const float dist = Square(p1->first.x-p2->first.x)+Square(p1->first.y-p2->first.y);
if (dist <= Square(p1->first.size) && dist != 0.f)
const float dist = Square(p1.first.x - p2.first.x) + Square(p1.first.y - p2.first.y);
if (dist <= Square(p1.first.size) && dist != 0.f)
{
if (p1->first.response < p2->first.response)
p1->second = true; // mark as duplicate key point
if (p1.first.response < p2.first.response)
p1.second = true; // mark as duplicate key point
else
p2->second = true; // mark as duplicate key point
p2.second = true; // mark as duplicate key point
break; // no other point can be so close, so skip to the next iteration
}
}
Expand All @@ -280,11 +280,11 @@ void AKAZE::Feature_Detection(std::vector<AKAZEKeypoint>& kpts) const
#ifdef OPENMVG_USE_OPENMP
#pragma omp parallel for schedule(dynamic)
#endif
for( int p = 0; p < options_.iNbOctave; ++p )
for (int p = 0; p < options_.iNbOctave; ++p )
{
const float ratio = (float) (1 << p);

for( int q = 0; q < options_.iNbSlicePerOctave; ++q )
for (int q = 0; q < options_.iNbSlicePerOctave; ++q )
{
const float sigma_cur = Sigma( options_.fSigma0 , p , q , options_.iNbSlicePerOctave );
const Image<float> & LDetHess = evolution_[options_.iNbSlicePerOctave * p + q].Lhess;
Expand Down
2 changes: 1 addition & 1 deletion src/openMVG/features/akaze/AKAZE.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class AKAZE {
private:

Params options_; ///< Configuration options for AKAZE
std::vector<TEvolution> evolution_; ///< Vector of nonlinear diffusion evolution (Scale Space)
std::vector<TEvolution> evolution_; ///< Vector of nonlinear diffusion evolution (Scale Space)
image::Image<float> in_; ///< Input image

public:
Expand Down
2 changes: 1 addition & 1 deletion src/openMVG/features/akaze/image_describer_akaze.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AKAZE_Image_describer : public Image_describer

bool Set_configuration_preset(EDESCRIBER_PRESET preset) override
{
switch(preset)
switch (preset)
{
case NORMAL_PRESET:
params_.options_.fThreshold = features::AKAZE::Params().fThreshold;
Expand Down
Loading

0 comments on commit a968c43

Please sign in to comment.