Skip to content

Commit 802be54

Browse files
committed
[colorCheckerDetection] Add option to launch the detection process only for images with a name matching a filter.
[hdr merging] Forward the suffix "_macbeth" to the hdr image name if at least one of the merged images has a name suffixed with that.
1 parent 8676edd commit 802be54

File tree

2 files changed

+52
-24
lines changed

2 files changed

+52
-24
lines changed

src/software/pipeline/main_LdrToHdrMerge.cpp

+21-7
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ using namespace aliceVision;
3737
namespace po = boost::program_options;
3838
namespace fs = boost::filesystem;
3939

40-
std::string getHdrImagePath(const std::string& outputPath, std::size_t g, const std::string& rootname = "")
40+
std::string getHdrImagePath(const std::string& outputPath, std::size_t g, const std::string& rootname = "", bool macbeth = false)
4141
{
4242
// Output image file path
4343
std::stringstream sstream;
4444
if (rootname == "")
4545
{
46-
sstream << "hdr_" << std::setfill('0') << std::setw(4) << g << ".exr";
46+
sstream << "hdr_" << std::setfill('0') << std::setw(4) << g << (macbeth ? "_macbeth" : "") << ".exr";
4747
}
4848
else
4949
{
50-
sstream << rootname << ".exr";
50+
sstream << rootname << (macbeth ? "_macbeth" : "") << ".exr";
5151
}
5252
const std::string hdrImagePath = (fs::path(outputPath) / sstream.str()).string();
5353
return hdrImagePath;
@@ -354,7 +354,7 @@ int aliceVision_main(int argc, char** argv)
354354
std::shared_ptr<sfmData::View> hdrView;
355355

356356
const auto & group = groups[g];
357-
357+
358358
if (group.size() == 1)
359359
{
360360
hdrView = std::make_shared<sfmData::View>(*group.at(0));
@@ -370,8 +370,18 @@ int aliceVision_main(int argc, char** argv)
370370
}
371371
if (!byPass)
372372
{
373-
boost::filesystem::path p(targetViews[g]->getImagePath());
374-
const std::string hdrImagePath = getHdrImagePath(outputPath, pos, keepSourceImageName ? p.stem().string() : "");
373+
bool macbeth = false;
374+
for(int k = 0; k < group.size(); k++)
375+
{
376+
const std::string fname = group[k]->getImagePath();
377+
boost::filesystem::path p(fname);
378+
macbeth = macbeth || (p.stem().string().find("_macbeth") != std::string::npos);
379+
}
380+
const std::string tgt_name = targetViews[g]->getImagePath();
381+
macbeth = macbeth && ((tgt_name.find("_macbeth") == std::string::npos) || !keepSourceImageName);
382+
383+
boost::filesystem::path p(tgt_name);
384+
const std::string hdrImagePath = getHdrImagePath(outputPath, pos, keepSourceImageName ? p.stem().string() : "", macbeth);
375385
hdrView->setImagePath(hdrImagePath);
376386
}
377387
hdrView->addMetadata("AliceVision:ColorSpace", image::EImageColorSpace_enumToString(mergedColorSpace));
@@ -427,11 +437,14 @@ int aliceVision_main(int argc, char** argv)
427437
std::shared_ptr<sfmData::View> targetView = targetViews[g];
428438
std::vector<sfmData::ExposureSetting> exposuresSetting(group.size());
429439

440+
bool macbeth = false;
430441
// Load all images of the group
431442
for(std::size_t i = 0; i < group.size(); ++i)
432443
{
433444
const std::string filepath = group[i]->getImagePath();
434445
ALICEVISION_LOG_INFO("Load " << filepath);
446+
boost::filesystem::path p(filepath);
447+
macbeth = macbeth || (p.stem().string().find("_macbeth") != std::string::npos);
435448

436449
image::ImageReadOptions options;
437450
options.workingColorSpace = workingColorSpace;
@@ -493,7 +506,8 @@ int aliceVision_main(int argc, char** argv)
493506
}
494507

495508
boost::filesystem::path p(targetView->getImagePath());
496-
const std::string hdrImagePath = getHdrImagePath(outputPath, pos, keepSourceImageName ? p.stem().string() : "");
509+
macbeth = macbeth && ((p.stem().string().find("_macbeth") == std::string::npos) || !keepSourceImageName);
510+
const std::string hdrImagePath = getHdrImagePath(outputPath, pos, keepSourceImageName ? p.stem().string() : "", macbeth);
497511

498512
// Write an image with parameters from the target view
499513
std::map<std::string, std::string> viewMetadata = targetView->getMetadata();

src/software/utils/main_colorCheckerDetection.cpp

+31-17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <boost/program_options.hpp>
2121
#include <boost/property_tree/ptree.hpp>
2222
#include <boost/property_tree/json_parser.hpp>
23+
#include <boost/regex.hpp>
2324

2425
#include <opencv2/core.hpp>
2526
#include <opencv2/imgproc/imgproc.hpp>
@@ -406,6 +407,8 @@ int aliceVision_main(int argc, char** argv)
406407
// user optional parameters
407408
bool debug = false;
408409
unsigned int maxCountByImage = 1;
410+
bool processAllImages = true;
411+
std::string filter = "*_macbeth.*";
409412

410413
po::options_description inputParams("Required parameters");
411414
inputParams.add_options()
@@ -416,8 +419,11 @@ int aliceVision_main(int argc, char** argv)
416419

417420
po::options_description optionalParams("Optional parameters");
418421
optionalParams.add_options()
419-
("debug", po::value<bool>(&debug),
420-
"Output debug data.")
422+
("debug", po::value<bool>(&debug), "Output debug data.")
423+
("processAllImages", po::value<bool>(&processAllImages)->default_value(processAllImages),
424+
"If True, process all available images.")
425+
("filter", po::value<std::string>(&filter)->default_value(filter),
426+
"Regular expression to select images to be processed.")
421427
("maxCount", po::value<unsigned int>(&maxCountByImage),
422428
"Maximum color charts count to detect in a single image.");
423429

@@ -458,17 +464,20 @@ int aliceVision_main(int argc, char** argv)
458464
{
459465
const sfmData::View& view = *(viewIt.second);
460466

461-
ALICEVISION_LOG_INFO(++counter << "/" << sfmData.getViews().size() << " - Process image at: '" << view.getImagePath() << "'.");
462-
ImageOptions imgOpt = {
463-
view.getImagePath(),
464-
std::to_string(view.getViewId()),
465-
view.getMetadataBodySerialNumber(),
466-
view.getMetadataLensSerialNumber() };
467-
imgOpt.readOptions.workingColorSpace = image::EImageColorSpace::SRGB;
468-
imgOpt.readOptions.rawColorInterpretation = image::ERawColorInterpretation_stringToEnum(view.getRawColorInterpretation());
469-
detectColorChecker(detectedCCheckers, imgOpt, settings);
467+
boost::filesystem::path p(view.getImagePath());
468+
const std::regex regex = utils::filterToRegex(filter);
469+
if(processAllImages || std::regex_match(p.generic_string(), regex))
470+
{
471+
ALICEVISION_LOG_INFO(++counter << "/" << sfmData.getViews().size() << " - Process image at: '"
472+
<< view.getImagePath() << "'.");
473+
ImageOptions imgOpt = {view.getImagePath(), std::to_string(view.getViewId()),
474+
view.getMetadataBodySerialNumber(), view.getMetadataLensSerialNumber()};
475+
imgOpt.readOptions.workingColorSpace = image::EImageColorSpace::SRGB;
476+
imgOpt.readOptions.rawColorInterpretation =
477+
image::ERawColorInterpretation_stringToEnum(view.getRawColorInterpretation());
478+
detectColorChecker(detectedCCheckers, imgOpt, settings);
479+
}
470480
}
471-
472481
}
473482
else
474483
{
@@ -509,11 +518,16 @@ int aliceVision_main(int argc, char** argv)
509518
int counter = 0;
510519
for(const std::string& imgSrcPath : filesStrPaths)
511520
{
512-
ALICEVISION_LOG_INFO(++counter << "/" << size << " - Process image at: '" << imgSrcPath << "'.");
513-
ImageOptions imgOpt;
514-
imgOpt.imgFsPath = imgSrcPath;
515-
imgOpt.readOptions.workingColorSpace = image::EImageColorSpace::SRGB;
516-
detectColorChecker(detectedCCheckers, imgOpt, settings);
521+
boost::filesystem::path p(imgSrcPath);
522+
const std::regex regex = utils::filterToRegex(filter);
523+
if(processAllImages || std::regex_match(p.generic_string(), regex))
524+
{
525+
ALICEVISION_LOG_INFO(++counter << "/" << size << " - Process image at: '" << imgSrcPath << "'.");
526+
ImageOptions imgOpt;
527+
imgOpt.imgFsPath = imgSrcPath;
528+
imgOpt.readOptions.workingColorSpace = image::EImageColorSpace::SRGB;
529+
detectColorChecker(detectedCCheckers, imgOpt, settings);
530+
}
517531
}
518532

519533
}

0 commit comments

Comments
 (0)