Skip to content

Commit

Permalink
Merge branch 'alicevision:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Arch-Frost authored Feb 2, 2025
2 parents a697c64 + 11a2b6a commit 7db6428
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/software/convert/main_importKnownPoses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>
#include <regex>
#include <iostream>
#include <fstream>
#include <list>

#include <boost/property_tree/ptree.hpp>
Expand Down
1 change: 1 addition & 0 deletions src/software/pipeline/main_globalRotationEstimating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <boost/program_options.hpp>
#include <filesystem>
#include <fstream>

// These constants define the current software version.
// They must be updated when the command line is changed.
Expand Down
1 change: 1 addition & 0 deletions src/software/pipeline/main_nodalSfM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <filesystem>
#include <random>
#include <regex>
#include <fstream>

#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
Expand Down
1 change: 1 addition & 0 deletions src/software/pipeline/main_sfmBootstraping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <cstdlib>
#include <random>
#include <regex>
#include <fstream>

// These constants define the current software version.
// They must be updated when the command line is changed.
Expand Down
9 changes: 9 additions & 0 deletions src/software/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ if(ALICEVISION_BUILD_SFM)
${Boost_LIBRARIES}
)

alicevision_add_software(aliceVision_maskProcessing
SOURCE main_maskProcessing.cpp
FOLDER ${FOLDER_SOFTWARE_UTILS}
LINKS aliceVision_system
aliceVision_cmdline
aliceVision_image
${Boost_LIBRARIES}
)

if(ALICEVISION_HAVE_OPENCV)
target_link_libraries(aliceVision_imageProcessing_exe PRIVATE ${OpenCV_LIBS})
endif()
Expand Down
204 changes: 204 additions & 0 deletions src/software/utils/main_maskProcessing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// This file is part of the AliceVision project.
// Copyright (c) 2025 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include <aliceVision/cmdline/cmdline.hpp>
#include <aliceVision/system/main.hpp>
#include <aliceVision/image/io.hpp>

#include <boost/program_options.hpp>

#include <string>
#include <sstream>
#include <random>
#include <filesystem>

// These constants define the current software version.
// They must be updated when the command line is changed.
#define ALICEVISION_SOFTWARE_VERSION_MAJOR 1
#define ALICEVISION_SOFTWARE_VERSION_MINOR 0

using namespace aliceVision;

namespace po = boost::program_options;


namespace {

/**
* @brief operator method enum
*/
enum class EMaskOperator : unsigned char
{
OR = 0,
AND,
NOT
};

/**
* @brief Convert an EMaskOperator enum to its corresponding string
* @param[in] maskOperator The given EMaskOperator enum
* @return string
*/
std::string EMaskOperator_enumToString(EMaskOperator maskOperator)
{
switch (maskOperator)
{
case EMaskOperator::OR:
return "or";
case EMaskOperator::AND:
return "and";
case EMaskOperator::NOT:
return "not";
}
throw std::out_of_range("Invalid EMaskOperator enum");
}

/**
* @brief Convert a string to its corresponding EMaskOperator enum
* @param[in] MaskOperator The given string
* @return EMaskOperator enum
*/
EMaskOperator EMaskOperator_stringToEnum(const std::string& maskOperator)
{
std::string op = maskOperator;
std::transform(op.begin(), op.end(), op.begin(), ::tolower); // tolower

if (op == "or")
return EMaskOperator::OR;
if (op == "and")
return EMaskOperator::AND;
if (op == "not")
return EMaskOperator::NOT;


throw std::out_of_range("Invalid mask operator : " + maskOperator);
}

inline std::istream& operator>>(std::istream& in, EMaskOperator& maskOperator)
{
std::string token(std::istreambuf_iterator<char>(in), {});
maskOperator = EMaskOperator_stringToEnum(token);
return in;
}

inline std::ostream& operator<<(std::ostream& os, EMaskOperator e) { return os << EMaskOperator_enumToString(e); }

} // namespace


int aliceVision_main(int argc, char** argv)
{
// command-line parameters
std::vector<std::string> directoryNames;
std::string outDirectory;
EMaskOperator maskOperator = EMaskOperator::OR;

// clang-format off
po::options_description requiredParams("Required parameters");
requiredParams.add_options()
("inputs,i", po::value<std::vector<std::string>>(&directoryNames)->multitoken(),
"Path to directories to process.")
("output,o", po::value<std::string>(&outDirectory)->required(),
"Output directory.");

po::options_description optionalParams("Optional parameters");
optionalParams.add_options()
("operator", po::value<EMaskOperator>(&maskOperator)->default_value(maskOperator), "");
// clang-format on

CmdLine cmdline("AliceVision sfmMerge");
cmdline.add(requiredParams);
cmdline.add(optionalParams);
if (!cmdline.execute(argc, argv))
{
return EXIT_FAILURE;
}

if (directoryNames.empty())
{
ALICEVISION_LOG_ERROR("At least one directory should be given.");
return EXIT_FAILURE;
}

std::string path = directoryNames[0];
for (auto &p : std::filesystem::recursive_directory_iterator(path))
{
const std::filesystem::path refpath = p.path();
if (p.path().extension() != ".exr")
{
continue;
}

ALICEVISION_LOG_INFO("Processing " << refpath.string());

std::filesystem::path outputDirectoryPath(outDirectory);
std::filesystem::path outputPath = outputDirectoryPath / refpath.filename();


image::Image<unsigned char> img;
aliceVision::image::readImage(refpath.string(), img, image::EImageColorSpace::NO_CONVERSION);

if (maskOperator == EMaskOperator::NOT)
{
for (int i = 0; i < img.height(); i++)
{
for (int j = 0; j < img.width(); j++)
{
img(i, j) = (img(i, j) > 0)?0:255;
}
}
}
else
{
for (int otherDirIndex = 1; otherDirIndex < directoryNames.size(); otherDirIndex++)
{
std::filesystem::path otherPath(directoryNames[otherDirIndex]);

std::filesystem::path otherMaskPath = otherPath / refpath.filename();
if (!std::filesystem::exists(otherMaskPath))
{
continue;
}

image::Image<unsigned char> otherImg;
aliceVision::image::readImage(otherMaskPath.string(), otherImg, image::EImageColorSpace::NO_CONVERSION);

if (otherImg.width() != img.width())
{
continue;
}

if (otherImg.height() != img.height())
{
continue;
}


for (int i = 0; i < img.height(); i++)
{
for (int j = 0; j < img.width(); j++)
{
if (maskOperator == EMaskOperator::AND)
{
img(i, j) = img(i, j) & otherImg(i, j);
}
else if (maskOperator == EMaskOperator::OR)
{
img(i, j) = img(i, j) | otherImg(i, j);
}
}
}
}
}

aliceVision::image::ImageWriteOptions wopt;
aliceVision::image::writeImage(outputPath.string(), img, wopt);
}



return EXIT_SUCCESS;
}
1 change: 1 addition & 0 deletions src/software/utils/main_rigTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <boost/program_options.hpp>

#include <fstream>
#include <iostream>
#include <string>
#include <chrono>
Expand Down
Loading

0 comments on commit 7db6428

Please sign in to comment.