Skip to content

Commit

Permalink
Reformat src/aliceVision with latest clang-format rules
Browse files Browse the repository at this point in the history
Co-authored-by: Candice Bentéjac <[email protected]>
  • Loading branch information
cbentejac committed Oct 23, 2023
1 parent 6df3c5b commit 53da43a
Show file tree
Hide file tree
Showing 771 changed files with 76,483 additions and 87,765 deletions.
10 changes: 5 additions & 5 deletions src/aliceVision/alicevision_omp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <aliceVision/config.hpp>

#if ALICEVISION_IS_DEFINED(ALICEVISION_HAVE_OPENMP)
#include <omp.h>
#include <omp.h>
#else
using omp_lock_t = char;

Expand All @@ -19,9 +19,9 @@ inline void omp_set_num_threads(int num_threads) {}
inline int omp_get_num_procs() { return 1; }
inline void omp_set_nested(int nested) {}

inline void omp_init_lock(omp_lock_t *lock) {}
inline void omp_destroy_lock(omp_lock_t *lock) {}
inline void omp_init_lock(omp_lock_t* lock) {}
inline void omp_destroy_lock(omp_lock_t* lock) {}

inline void omp_set_lock(omp_lock_t *lock) {}
inline void omp_unset_lock(omp_lock_t *lock) {}
inline void omp_set_lock(omp_lock_t* lock) {}
inline void omp_unset_lock(omp_lock_t* lock) {}
#endif
218 changes: 109 additions & 109 deletions src/aliceVision/calibration/bestImages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,156 +12,156 @@
#include <iostream>
#include <assert.h>

namespace aliceVision{
namespace calibration{
namespace aliceVision {
namespace calibration {

void precomputeCellIndexes(const std::vector<std::vector<cv::Point2f> >& imagePoints,
void precomputeCellIndexes(const std::vector<std::vector<cv::Point2f>>& imagePoints,
const cv::Size& imageSize,
std::size_t calibGridSize,
std::vector<std::vector<std::size_t> >& cellIndexesPerImage)
std::vector<std::vector<std::size_t>>& cellIndexesPerImage)
{
float cellWidth = float(imageSize.width) / float(calibGridSize);
float cellHeight = float(imageSize.height) / float(calibGridSize);

for (const auto& pointbuf : imagePoints)
{
std::vector<std::size_t> imageCellIndexes;
// Points repartition in image
for (cv::Point2f point : pointbuf)
float cellWidth = float(imageSize.width) / float(calibGridSize);
float cellHeight = float(imageSize.height) / float(calibGridSize);

for (const auto& pointbuf : imagePoints)
{
// Compute the index of the point
std::size_t cellPointX = std::floor(point.x / cellWidth);
std::size_t cellPointY = std::floor(point.y / cellHeight);
std::size_t cellIndex = cellPointY * calibGridSize + cellPointX;
imageCellIndexes.push_back(cellIndex);
std::vector<std::size_t> imageCellIndexes;
// Points repartition in image
for (cv::Point2f point : pointbuf)
{
// Compute the index of the point
std::size_t cellPointX = std::floor(point.x / cellWidth);
std::size_t cellPointY = std::floor(point.y / cellHeight);
std::size_t cellIndex = cellPointY * calibGridSize + cellPointX;
imageCellIndexes.push_back(cellIndex);
}
cellIndexesPerImage.push_back(imageCellIndexes);
}
cellIndexesPerImage.push_back(imageCellIndexes);
}
}

void computeCellsWeight(const std::vector<std::size_t>& imagesIndexes,
const std::vector<std::vector<std::size_t> >& cellIndexesPerImage,
const std::vector<std::vector<std::size_t>>& cellIndexesPerImage,
std::size_t calibGridSize,
std::map<std::size_t, std::size_t>& cellsWeight)
{
//Init cell's weight to 0
for (std::size_t i = 0; i < calibGridSize * calibGridSize; ++i)
cellsWeight[i] = 0;

// Add weight into cells
for (const auto& imagesIndex : imagesIndexes)
{
std::vector<std::size_t> uniqueCellIndexes = cellIndexesPerImage[imagesIndex];
std::sort(uniqueCellIndexes.begin(), uniqueCellIndexes.end());
auto last = std::unique(uniqueCellIndexes.begin(), uniqueCellIndexes.end());
uniqueCellIndexes.erase(last, uniqueCellIndexes.end());

for (std::size_t cellIndex : uniqueCellIndexes)
// Init cell's weight to 0
for (std::size_t i = 0; i < calibGridSize * calibGridSize; ++i)
cellsWeight[i] = 0;

// Add weight into cells
for (const auto& imagesIndex : imagesIndexes)
{
++cellsWeight[cellIndex];
std::vector<std::size_t> uniqueCellIndexes = cellIndexesPerImage[imagesIndex];
std::sort(uniqueCellIndexes.begin(), uniqueCellIndexes.end());
auto last = std::unique(uniqueCellIndexes.begin(), uniqueCellIndexes.end());
uniqueCellIndexes.erase(last, uniqueCellIndexes.end());

for (std::size_t cellIndex : uniqueCellIndexes)
{
++cellsWeight[cellIndex];
}
}
}
}

void computeImageScores(const std::vector<std::size_t>& inputImagesIndexes,
const std::vector<std::vector<std::size_t> >& cellIndexesPerImage,
const std::vector<std::vector<std::size_t>>& cellIndexesPerImage,
const std::map<std::size_t, std::size_t>& cellsWeight,
std::vector<std::pair<float, std::size_t> >& imageScores)
std::vector<std::pair<float, std::size_t>>& imageScores)
{
// Compute the score of each image
for (const auto& inputImagesIndex : inputImagesIndexes)
{
const std::vector<std::size_t>& imageCellIndexes = cellIndexesPerImage[inputImagesIndex];
float imageScore = 0;
for (std::size_t cellIndex : imageCellIndexes)
// Compute the score of each image
for (const auto& inputImagesIndex : inputImagesIndexes)
{
imageScore += cellsWeight.at(cellIndex);
const std::vector<std::size_t>& imageCellIndexes = cellIndexesPerImage[inputImagesIndex];
float imageScore = 0;
for (std::size_t cellIndex : imageCellIndexes)
{
imageScore += cellsWeight.at(cellIndex);
}
// Normalize by the number of checker items.
// If the detector support occlusions of the checker the number of items may vary.
imageScore /= float(imageCellIndexes.size());
imageScores.emplace_back(imageScore, inputImagesIndex);
}
// Normalize by the number of checker items.
// If the detector support occlusions of the checker the number of items may vary.
imageScore /= float(imageCellIndexes.size());
imageScores.emplace_back(imageScore, inputImagesIndex);
}
}

void selectBestImages(const std::vector<std::vector<cv::Point2f> >& imagePoints,
void selectBestImages(const std::vector<std::vector<cv::Point2f>>& imagePoints,
const cv::Size& imageSize,
std::size_t maxCalibFrames,
std::size_t calibGridSize,
std::vector<float>& calibImageScore,
std::vector<std::size_t>& calibInputFrames,
std::vector<std::vector<cv::Point2f> >& calibImagePoints,
std::vector<std::vector<cv::Point2f>>& calibImagePoints,
std::vector<std::size_t>& remainingImagesIndexes)
{
std::vector<std::vector<std::size_t> > cellIndexesPerImage;
std::vector<std::vector<std::size_t>> cellIndexesPerImage;

// Precompute cell indexes per image
precomputeCellIndexes(imagePoints, imageSize, calibGridSize, cellIndexesPerImage);
// Precompute cell indexes per image
precomputeCellIndexes(imagePoints, imageSize, calibGridSize, cellIndexesPerImage);

// Init with 0, 1, 2, ...
remainingImagesIndexes.resize(imagePoints.size());
std::iota(remainingImagesIndexes.begin(), remainingImagesIndexes.end(), 0);
// Init with 0, 1, 2, ...
remainingImagesIndexes.resize(imagePoints.size());
std::iota(remainingImagesIndexes.begin(), remainingImagesIndexes.end(), 0);

std::vector<std::size_t> bestImagesIndexes;
if (maxCalibFrames < imagePoints.size())
{
while (bestImagesIndexes.size() < maxCalibFrames )
std::vector<std::size_t> bestImagesIndexes;
if (maxCalibFrames < imagePoints.size())
{
std::map<std::size_t, std::size_t> cellsWeight;
std::vector<std::pair<float, std::size_t> > imageScores;
// Count points in each cell of the grid
if (bestImagesIndexes.empty())
while (bestImagesIndexes.size() < maxCalibFrames)
{
std::map<std::size_t, std::size_t> cellsWeight;
std::vector<std::pair<float, std::size_t>> imageScores;
// Count points in each cell of the grid
if (bestImagesIndexes.empty())
computeCellsWeight(remainingImagesIndexes, cellIndexesPerImage, calibGridSize, cellsWeight);
else
computeCellsWeight(bestImagesIndexes, cellIndexesPerImage, calibGridSize, cellsWeight);

computeImageScores(remainingImagesIndexes, cellIndexesPerImage, cellsWeight, imageScores);

// Find best score
std::size_t bestImageIndex = std::numeric_limits<std::size_t>::max();
float bestScore = std::numeric_limits<float>::max();
for (const auto& imageScore : imageScores)
{
if (imageScore.first < bestScore)
{
bestScore = imageScore.first;
bestImageIndex = imageScore.second;
}
}
auto eraseIt = std::find(remainingImagesIndexes.begin(), remainingImagesIndexes.end(), bestImageIndex);
assert(bestScore != std::numeric_limits<float>::max());
assert(eraseIt != remainingImagesIndexes.end());
remainingImagesIndexes.erase(eraseIt);
bestImagesIndexes.push_back(bestImageIndex);
calibImageScore.push_back(bestScore);
}
}
else
{
ALICEVISION_LOG_DEBUG("Info: Less valid frames (" << imagePoints.size() << ") than specified maxCalibFrames (" << maxCalibFrames << ").");
bestImagesIndexes.resize(imagePoints.size());
std::iota(bestImagesIndexes.begin(), bestImagesIndexes.end(), 0);

std::map<std::size_t, std::size_t> cellsWeight;
computeCellsWeight(remainingImagesIndexes, cellIndexesPerImage, calibGridSize, cellsWeight);
else
computeCellsWeight(bestImagesIndexes, cellIndexesPerImage, calibGridSize, cellsWeight);

computeImageScores(remainingImagesIndexes, cellIndexesPerImage, cellsWeight, imageScores);
std::vector<std::pair<float, std::size_t>> imageScores;
computeImageScores(remainingImagesIndexes, cellIndexesPerImage, cellsWeight, imageScores);

// Find best score
std::size_t bestImageIndex = std::numeric_limits<std::size_t>::max();
float bestScore = std::numeric_limits<float>::max();
for (const auto& imageScore: imageScores)
{
if (imageScore.first < bestScore)
for (auto imgScore : imageScores)
{
bestScore = imageScore.first;
bestImageIndex = imageScore.second;
calibImageScore.push_back(imgScore.first);
}
}
auto eraseIt = std::find(remainingImagesIndexes.begin(), remainingImagesIndexes.end(), bestImageIndex);
assert(bestScore != std::numeric_limits<float>::max());
assert(eraseIt != remainingImagesIndexes.end());
remainingImagesIndexes.erase(eraseIt);
bestImagesIndexes.push_back(bestImageIndex);
calibImageScore.push_back(bestScore);
}
}
else
{
ALICEVISION_LOG_DEBUG("Info: Less valid frames (" << imagePoints.size() << ") than specified maxCalibFrames (" << maxCalibFrames << ").");
bestImagesIndexes.resize(imagePoints.size());
std::iota(bestImagesIndexes.begin(), bestImagesIndexes.end(), 0);

std::map<std::size_t, std::size_t> cellsWeight;
computeCellsWeight(remainingImagesIndexes, cellIndexesPerImage, calibGridSize, cellsWeight);

std::vector<std::pair<float, std::size_t> > imageScores;
computeImageScores(remainingImagesIndexes, cellIndexesPerImage, cellsWeight, imageScores);

for(auto imgScore: imageScores)
{
calibImageScore.push_back(imgScore.first);
}
}

assert(bestImagesIndexes.size() == std::min(maxCalibFrames, imagePoints.size()));
assert(bestImagesIndexes.size() == std::min(maxCalibFrames, imagePoints.size()));

for (const auto& origI : bestImagesIndexes)
{
calibImagePoints.push_back(imagePoints[origI]);
calibInputFrames.push_back(origI);
}
for (const auto& origI : bestImagesIndexes)
{
calibImagePoints.push_back(imagePoints[origI]);
calibInputFrames.push_back(origI);
}
}

}//namespace calibration
}//namespace aliceVision
} // namespace calibration
} // namespace aliceVision
23 changes: 11 additions & 12 deletions src/aliceVision/calibration/bestImages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <map>
#include <opencv2/opencv.hpp>

namespace aliceVision{
namespace calibration{
namespace aliceVision {
namespace calibration {

/**
* @brief This function computes cell indexes per image.
Expand All @@ -21,10 +21,10 @@ namespace calibration{
* @param[in] calibGridSize The number of cells per each image dimension.
* @param[out] cellIndexesPerImage The id of the cell for each point of the image sequence.
*/
void precomputeCellIndexes(const std::vector<std::vector<cv::Point2f> >& imagePoints,
void precomputeCellIndexes(const std::vector<std::vector<cv::Point2f>>& imagePoints,
const cv::Size& imageSize,
std::size_t calibGridSize,
std::vector<std::vector<std::size_t> >& cellIndexesPerImage);
std::vector<std::vector<std::size_t>>& cellIndexesPerImage);

/**
* @brief This function counts the number of points in each cell of the grid.
Expand All @@ -35,7 +35,7 @@ void precomputeCellIndexes(const std::vector<std::vector<cv::Point2f> >& imagePo
* @param[out] cellsWeight The number of points for each cell id.
*/
void computeCellsWeight(const std::vector<std::size_t>& imagesIndexes,
const std::vector<std::vector<std::size_t> >& cellIndexesPerImage,
const std::vector<std::vector<std::size_t>>& cellIndexesPerImage,
std::size_t calibGridSize,
std::map<std::size_t, std::size_t>& cellsWeight);

Expand All @@ -48,9 +48,9 @@ void computeCellsWeight(const std::vector<std::size_t>& imagesIndexes,
* @param[out] imageScores The score of each image.
*/
void computeImageScores(const std::vector<std::size_t>& inputImagesIndexes,
const std::vector<std::vector<std::size_t> >& cellIndexesPerImage,
const std::vector<std::vector<std::size_t>>& cellIndexesPerImage,
const std::map<std::size_t, std::size_t>& cellsWeight,
std::vector<std::pair<float, std::size_t> >& imageScores);
std::vector<std::pair<float, std::size_t>>& imageScores);

/**
* @brief This function selects the best images based on distribution of calibration landmarks in images.
Expand All @@ -64,15 +64,14 @@ void computeImageScores(const std::vector<std::size_t>& inputImagesIndexes,
* @param[out] calibImagePoints Set of points for each selected image.
* @param[out] remainingImagesIndexes Indexes of non-selected images from validFrames.
*/
void selectBestImages(const std::vector<std::vector<cv::Point2f> >& imagePoints,
void selectBestImages(const std::vector<std::vector<cv::Point2f>>& imagePoints,
const cv::Size& imageSize,
std::size_t maxCalibFrames,
std::size_t calibGridSize,
std::vector<float>& calibImageScore,
std::vector<std::size_t>& calibInputFrames,
std::vector<std::vector<cv::Point2f> >& calibImagePoints,
std::vector<std::vector<cv::Point2f>>& calibImagePoints,
std::vector<std::size_t>& remainingImagesIndexes);

}//namespace calibration
}//namespace aliceVision

} // namespace calibration
} // namespace aliceVision
Loading

0 comments on commit 53da43a

Please sign in to comment.