Skip to content

Commit

Permalink
[colorCheckerDetection] Add option to launch the detection process on…
Browse files Browse the repository at this point in the history
…ly 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.
  • Loading branch information
demoulinv committed Sep 14, 2023
1 parent 28ac6c7 commit 1bd7bbb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 24 deletions.
28 changes: 21 additions & 7 deletions src/software/pipeline/main_LdrToHdrMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ using namespace aliceVision;
namespace po = boost::program_options;
namespace fs = boost::filesystem;

std::string getHdrImagePath(const std::string& outputPath, std::size_t g, const std::string& rootname = "")
std::string getHdrImagePath(const std::string& outputPath, std::size_t g, const std::string& rootname = "", bool macbeth = false)
{
// Output image file path
std::stringstream sstream;
if (rootname == "")
{
sstream << "hdr_" << std::setfill('0') << std::setw(4) << g << ".exr";
sstream << "hdr_" << std::setfill('0') << std::setw(4) << g << (macbeth ? "_macbeth" : "") << ".exr";
}
else
{
sstream << rootname << ".exr";
sstream << rootname << (macbeth ? "_macbeth" : "") << ".exr";
}
const std::string hdrImagePath = (fs::path(outputPath) / sstream.str()).string();
return hdrImagePath;
Expand Down Expand Up @@ -354,7 +354,7 @@ int aliceVision_main(int argc, char** argv)
std::shared_ptr<sfmData::View> hdrView;

const auto & group = groups[g];

if (group.size() == 1)
{
hdrView = std::make_shared<sfmData::View>(*group.at(0));
Expand All @@ -370,8 +370,18 @@ int aliceVision_main(int argc, char** argv)
}
if (!byPass)
{
boost::filesystem::path p(targetViews[g]->getImage().getImagePath());
const std::string hdrImagePath = getHdrImagePath(outputPath, pos, keepSourceImageName ? p.stem().string() : "");
bool macbeth = false;
for(int k = 0; k < group.size(); k++)
{
const std::string fname = group[k]->getImagePath();
boost::filesystem::path p(fname);
macbeth = macbeth || (p.stem().string().find("_macbeth") != std::string::npos);
}
const std::string tgt_name = targetViews[g]->getImage().getImagePath();
macbeth = macbeth && ((tgt_name.find("_macbeth") == std::string::npos) || !keepSourceImageName);

boost::filesystem::path p(tgt_name);
const std::string hdrImagePath = getHdrImagePath(outputPath, pos, keepSourceImageName ? p.stem().string() : "", macbeth);
hdrView->getImage().setImagePath(hdrImagePath);
}
hdrView->getImage().addMetadata("AliceVision:ColorSpace", image::EImageColorSpace_enumToString(mergedColorSpace));
Expand Down Expand Up @@ -427,11 +437,14 @@ int aliceVision_main(int argc, char** argv)
std::shared_ptr<sfmData::View> targetView = targetViews[g];
std::vector<sfmData::ExposureSetting> exposuresSetting(group.size());

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

image::ImageReadOptions options;
options.workingColorSpace = workingColorSpace;
Expand Down Expand Up @@ -493,7 +506,8 @@ int aliceVision_main(int argc, char** argv)
}

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

// Write an image with parameters from the target view
std::map<std::string, std::string> viewMetadata = targetView->getImage().getMetadata();
Expand Down
48 changes: 31 additions & 17 deletions src/software/utils/main_colorCheckerDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <boost/program_options.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/regex.hpp>

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

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

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

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

ALICEVISION_LOG_INFO(++counter << "/" << sfmData.getViews().size() << " - Process image at: '" << view.getImage().getImagePath() << "'.");
ImageOptions imgOpt = {
view.getImage().getImagePath(),
std::to_string(view.getViewId()),
view.getImage().getMetadataBodySerialNumber(),
view.getImage().getMetadataLensSerialNumber() };
imgOpt.readOptions.workingColorSpace = image::EImageColorSpace::SRGB;
imgOpt.readOptions.rawColorInterpretation = image::ERawColorInterpretation_stringToEnum(view.getImage().getRawColorInterpretation());
detectColorChecker(detectedCCheckers, imgOpt, settings);
boost::filesystem::path p(view.getImage().getImagePath());
const std::regex regex = utils::filterToRegex(filter);
if(processAllImages || std::regex_match(p.generic_string(), regex))
{
ALICEVISION_LOG_INFO(++counter << "/" << sfmData.getViews().size() << " - Process image at: '"
<< view.getImage().getImagePath() << "'.");
ImageOptions imgOpt = {view.getImage().getImagePath(), std::to_string(view.getViewId()),
view.getImage().getMetadataBodySerialNumber(), view.getImage().getMetadataLensSerialNumber()};
imgOpt.readOptions.workingColorSpace = image::EImageColorSpace::SRGB;
imgOpt.readOptions.rawColorInterpretation =
image::ERawColorInterpretation_stringToEnum(view.getImage().getRawColorInterpretation());
detectColorChecker(detectedCCheckers, imgOpt, settings);
}
}

}
else
{
Expand Down Expand Up @@ -509,11 +518,16 @@ int aliceVision_main(int argc, char** argv)
int counter = 0;
for(const std::string& imgSrcPath : filesStrPaths)
{
ALICEVISION_LOG_INFO(++counter << "/" << size << " - Process image at: '" << imgSrcPath << "'.");
ImageOptions imgOpt;
imgOpt.imgFsPath = imgSrcPath;
imgOpt.readOptions.workingColorSpace = image::EImageColorSpace::SRGB;
detectColorChecker(detectedCCheckers, imgOpt, settings);
boost::filesystem::path p(imgSrcPath);
const std::regex regex = utils::filterToRegex(filter);
if(processAllImages || std::regex_match(p.generic_string(), regex))
{
ALICEVISION_LOG_INFO(++counter << "/" << size << " - Process image at: '" << imgSrcPath << "'.");
ImageOptions imgOpt;
imgOpt.imgFsPath = imgSrcPath;
imgOpt.readOptions.workingColorSpace = image::EImageColorSpace::SRGB;
detectColorChecker(detectedCCheckers, imgOpt, settings);
}
}

}
Expand Down

0 comments on commit 1bd7bbb

Please sign in to comment.