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

Image processing regex management update #1774

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
48 changes: 31 additions & 17 deletions src/software/utils/main_imageProcessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
// These constants define the current software version.
// They must be updated when the command line is changed.
#define ALICEVISION_SOFTWARE_VERSION_MAJOR 3
#define ALICEVISION_SOFTWARE_VERSION_MINOR 3
#define ALICEVISION_SOFTWARE_VERSION_MINOR 4

using namespace aliceVision;
namespace po = boost::program_options;
Expand Down Expand Up @@ -1028,7 +1028,8 @@ int aliceVision_main(int argc, char* argv[])
requiredParams.add_options()
("input,i", po::value<std::string>(&inputExpression)->default_value(inputExpression),
"SfMData file input, image filenames or regex(es) on the image file path (supported regex: '#' matches a "
"single digit, '@' one or more digits, '?' one character and '*' zero or more).")
"single digit, '@' one or more digits, '?' one character and '*' zero or more)."
"Argument must be between quotes if regex are used.")
("inputFolders", po::value<std::vector<std::string>>(&inputFolders)->multitoken(),
"Use images from specific folder(s) instead of those specify in the SfMData file.")
("output,o", po::value<std::string>(&outputPath)->required(),
Expand Down Expand Up @@ -1509,34 +1510,29 @@ int aliceVision_main(int argc, char* argv[])
const fs::path inputPath(inputExpression);
std::vector<std::string> filesStrPaths;

// If sfmInputDataFilename is empty use imageFolders instead
if (inputExpression.empty())
{
// Get supported files
filesStrPaths =
utils::getFilesPathsFromFolders(inputFolders, [](const fs::path& path) { return image::isSupported(path.extension().string()); });
}
else if (fs::is_regular_file(inputPath))
{
filesStrPaths.push_back(inputPath.string());
}
else
{
// If you try to use both a regex-like filter expression and folders as input
if (!inputFolders.empty())
if (inputFolders.empty())
{
ALICEVISION_LOG_WARNING("InputFolders and filter expression cannot be used at the same time, InputFolders are ignored here.");
inputFolders.push_back(inputPath.parent_path().generic_string());
}

if (fs::is_regular_file(inputPath))
const std::regex regex = utils::filterToRegex(inputExpression);
for (const auto& inputFolder : inputFolders)
{
filesStrPaths.push_back(inputPath.string());
}
else
{
ALICEVISION_LOG_INFO("Working directory Path '" + inputPath.parent_path().generic_string() + "'.");

const std::regex regex = utils::filterToRegex(inputExpression);
// Get supported files in inputPath directory which matches our regex filter
filesStrPaths = utils::getFilesPathsFromFolder(inputPath.parent_path().generic_string(), [&regex](const fs::path& path) {
std::vector<std::string> currFilesStrPaths = utils::getFilesPathsFromFolder(inputFolder, [&regex](const fs::path& path) {
return image::isSupported(path.extension().string()) && std::regex_match(path.generic_string(), regex);
});
filesStrPaths.insert(filesStrPaths.end(), currFilesStrPaths.begin(), currFilesStrPaths.end());
}
}

Expand Down Expand Up @@ -1605,10 +1601,28 @@ int aliceVision_main(int argc, char* argv[])
outputFilePath = (fs::path(outputPath).parent_path() / (filename + outputExt)).generic_string();
ALICEVISION_LOG_WARNING("Extension " << userExt << " is not supported! Output image saved in " << outputFilePath);
}
// Create output directory if it does not exist
if (!fs::exists(fs::path(outputPath).parent_path()))
{
if (!fs::create_directory(fs::path(outputPath).parent_path()))
{
ALICEVISION_LOG_ERROR("Unexisting directory " << fs::path(outputPath).parent_path().generic_string() << " cannot be created");
return EXIT_FAILURE;
}
}
}
else
{
outputFilePath = (fs::path(outputPath) / (filename + outputExt)).generic_string();
// Create output directory if it does not exist
if (!fs::exists(fs::path(outputPath)))
{
if (!fs::create_directory(fs::path(outputPath)))
{
ALICEVISION_LOG_ERROR("Unexisting directory " << outputPath << " cannot be created");
return EXIT_FAILURE;
}
}
}

image::DCPProfile dcpProf;
Expand Down
Loading