Skip to content

Commit

Permalink
Merge pull request #1367 from alicevision/dev/disableCompositingTiling
Browse files Browse the repository at this point in the history
[Panorama] New option to disable compositing tiling
  • Loading branch information
fabiencastan authored Mar 5, 2023
2 parents 24e7f90 + 7f738a2 commit 18a6568
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 59 deletions.
68 changes: 51 additions & 17 deletions src/software/pipeline/main_panoramaCompositing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,17 @@ bool processImage(const PanoramaMap& panoramaMap, const sfmData::SfMData& sfmDat
return false;
}

const std::string warpedPath = sfmData.getViews().at(viewReference)->getMetadata().at("AliceVision:warpedPath");
std::string warpedPath;

if (viewReference==UndefinedIndexT)
{
warpedPath = "panorama";
}
else
{
warpedPath = sfmData.getViews().at(viewReference)->getMetadata().at("AliceVision:warpedPath");
}

const std::string outputFilePath = (fs::path(outputFolder) / (warpedPath + ".exr")).string();
image::Image<image::RGBAfColor>& output = compositer->getOutput();

Expand Down Expand Up @@ -609,6 +619,7 @@ int aliceVision_main(int argc, char** argv)
int maxThreads = 1;
bool showBorders = false;
bool showSeams = false;
bool useTiling = true;

image::EStorageDataType storageDataType = image::EStorageDataType::Float;

Expand All @@ -626,9 +637,10 @@ int aliceVision_main(int argc, char** argv)
"storageDataType", po::value<image::EStorageDataType>(&storageDataType)->default_value(storageDataType),
("Storage data type: " + image::EStorageDataType_informations()).c_str())(
"rangeIteration", po::value<int>(&rangeIteration)->default_value(rangeIteration),
"Range chunk id.")("rangeSize", po::value<int>(&rangeSize)->default_value(rangeSize), "Range size.")(
"maxThreads", po::value<int>(&maxThreads)->default_value(maxThreads), "max number of threads to use.")(
"labels,l", po::value<std::string>(&labelsFilepath)->required(), "Labels image from seams estimation.");
"Range chunk id.")("rangeSize", po::value<int>(&rangeSize)->default_value(rangeSize), "Range size.")
("maxThreads", po::value<int>(&maxThreads)->default_value(maxThreads), "max number of threads to use.")
("labels,l", po::value<std::string>(&labelsFilepath)->required(), "Labels image from seams estimation.")
("useTiling,n", po::value<bool>(&useTiling)->default_value(useTiling), "use tiling for compositing.");

CmdLine cmdline(
"Performs the panorama stiching of warped images, with an option to use constraints from precomputed seams maps.\n"
Expand Down Expand Up @@ -684,6 +696,11 @@ int aliceVision_main(int argc, char** argv)

// Define range to compute
const int viewsCount = sfmData.getViews().size();
if (!useTiling)
{
rangeIteration = 0;
rangeSize = 1;
}
if(rangeIteration != -1)
{
if(rangeIteration < 0 || rangeSize < 0)
Expand Down Expand Up @@ -749,26 +766,43 @@ int aliceVision_main(int argc, char** argv)

bool succeeded = true;

for(std::size_t posReference = 0; posReference < chunk.size(); posReference++)
if (useTiling)
{
ALICEVISION_LOG_INFO("processing input region " << posReference + 1 << "/" << chunk.size());
for(std::size_t posReference = 0; posReference < chunk.size(); posReference++)
{
ALICEVISION_LOG_INFO("processing input region " << posReference + 1 << "/" << chunk.size());

const IndexT viewReference = chunk[posReference];
if(!sfmData.isPoseAndIntrinsicDefined(viewReference))
continue;
const IndexT viewReference = chunk[posReference];
if(!sfmData.isPoseAndIntrinsicDefined(viewReference))
continue;

BoundingBox referenceBoundingBox;
if(!panoramaMap->getBoundingBox(referenceBoundingBox, viewReference))
{
ALICEVISION_LOG_ERROR("Invalid view ID as reference");
return EXIT_FAILURE;
}
BoundingBox referenceBoundingBox;
if(!panoramaMap->getBoundingBox(referenceBoundingBox, viewReference))
{
ALICEVISION_LOG_ERROR("Invalid view ID as reference");
return EXIT_FAILURE;
}

if(!processImage(*panoramaMap, sfmData, compositerType, warpingFolder, labelsFilepath, outputFolder,
storageDataType, viewReference, referenceBoundingBox, showBorders, showSeams))
{
succeeded = false;
continue;
}
}
}
else
{
BoundingBox referenceBoundingBox;
referenceBoundingBox.left = 0;
referenceBoundingBox.top = 0;
referenceBoundingBox.width = panoramaMap->getWidth();
referenceBoundingBox.height = panoramaMap->getHeight();

if(!processImage(*panoramaMap, sfmData, compositerType, warpingFolder, labelsFilepath, outputFolder,
storageDataType, viewReference, referenceBoundingBox, showBorders, showSeams))
storageDataType, UndefinedIndexT, referenceBoundingBox, showBorders, showSeams))
{
succeeded = false;
continue;
}
}

Expand Down
84 changes: 42 additions & 42 deletions src/software/pipeline/main_panoramaMerging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int aliceVision_main(int argc, char** argv)
std::string outputPanoramaPath;
image::EStorageDataType storageDataType = image::EStorageDataType::Float;
const size_t tileSize = 256;
bool useTiling = true;

// Description of mandatory parameters
po::options_description requiredParams("Required parameters");
Expand All @@ -57,7 +58,8 @@ int aliceVision_main(int argc, char** argv)
// Description of optional parameters
po::options_description optionalParams("Optional parameters");
optionalParams.add_options()
("storageDataType", po::value<image::EStorageDataType>(&storageDataType)->default_value(storageDataType), ("Storage data type: " + image::EStorageDataType_informations()).c_str());
("storageDataType", po::value<image::EStorageDataType>(&storageDataType)->default_value(storageDataType), ("Storage data type: " + image::EStorageDataType_informations()).c_str())
("useTiling,n", po::value<bool>(&useTiling)->default_value(useTiling), "use tiling for compositing.");

CmdLine cmdline(
"Merges all the image tiles created by the PanoramaCompositing.\n"
Expand Down Expand Up @@ -89,45 +91,52 @@ int aliceVision_main(int argc, char** argv)
}


int panoramaWidth = 0;
int panoramaHeight = 0;
oiio::ParamValueList metadata;

for (auto viewItem : sfmData.getViews())
std::vector<std::pair<IndexT, std::string>> sourcesList;
if (useTiling)
{
IndexT viewId = viewItem.first;
if(!sfmData.isPoseAndIntrinsicDefined(viewId))
continue;
for (auto viewItem : sfmData.getViews())
{
IndexT viewId = viewItem.first;
if(!sfmData.isPoseAndIntrinsicDefined(viewId))
{
continue;
}

const std::string warpedPath = viewItem.second->getMetadata().at("AliceVision:warpedPath");
const std::string warpedPath = viewItem.second->getMetadata().at("AliceVision:warpedPath");

// Get composited image path
const std::string imagePath = (fs::path(compositingFolder) / (warpedPath + ".exr")).string();
// Get composited image path
const std::string imagePath = (fs::path(compositingFolder) / (warpedPath + ".exr")).string();

// Get offset
metadata = image::readImageMetadata(imagePath);
panoramaWidth = metadata.find("AliceVision:panoramaWidth")->get_int();
panoramaHeight = metadata.find("AliceVision:panoramaHeight")->get_int();
break;
sourcesList.push_back(std::make_pair(viewId, imagePath));
}
}
else
{
sourcesList.push_back(std::make_pair(0, (fs::path(compositingFolder) / "panorama.exr").string()));
}

if (sourcesList.size() == 0)
{
ALICEVISION_LOG_ERROR("Invalid number of sources");
return EXIT_FAILURE;
}

int panoramaWidth = 0;
int panoramaHeight = 0;
oiio::ParamValueList metadata;

auto sourceInput = sourcesList[0];
metadata = image::readImageMetadata(sourceInput.second);
panoramaWidth = metadata.find("AliceVision:panoramaWidth")->get_int();
panoramaHeight = metadata.find("AliceVision:panoramaHeight")->get_int();

int tileCountWidth = std::ceil(double(panoramaWidth) / double(tileSize));
int tileCountHeight = std::ceil(double(panoramaHeight) / double(tileSize));


std::map<std::pair<int, int>, IndexT> fullTiles;
for (auto viewItem : sfmData.getViews())
for (auto sourceItem : sourcesList)
{
IndexT viewId = viewItem.first;
if(!sfmData.isPoseAndIntrinsicDefined(viewId))
{
continue;
}

const std::string warpedPath = viewItem.second->getMetadata().at("AliceVision:warpedPath");

// Get composited image path
const std::string imagePath = (fs::path(compositingFolder) / (warpedPath + ".exr")).string();
std::string imagePath = sourceItem.second;

// Get offset
int width = 0;
Expand Down Expand Up @@ -167,7 +176,7 @@ int aliceVision_main(int argc, char** argv)

if (fullTiles.find(pos) == fullTiles.end())
{
fullTiles[pos] = viewId;
fullTiles[pos] = sourceItem.first;
}
}
}
Expand All @@ -194,18 +203,9 @@ int aliceVision_main(int argc, char** argv)
};
image::Image<TileInfo> tiles(tileCountWidth, tileCountHeight, true, {false, 0, nullptr});

for (auto viewItem : sfmData.getViews())
for (auto sourceItem : sourcesList)
{
IndexT viewId = viewItem.first;
if(!sfmData.isPoseAndIntrinsicDefined(viewId))
{
continue;
}

const std::string warpedPath = viewItem.second->getMetadata().at("AliceVision:warpedPath");

// Get composited image path
const std::string imagePath = (fs::path(compositingFolder) / (warpedPath + ".exr")).string();
std::string imagePath = sourceItem.second;

// Get offset
int width = 0;
Expand Down Expand Up @@ -260,7 +260,7 @@ int aliceVision_main(int argc, char** argv)
pos.second = ty;
if (fullTiles.find(pos) != fullTiles.end())
{
if (fullTiles[pos] != viewId)
if (fullTiles[pos] != sourceItem.first)
{
continue;
}
Expand Down

0 comments on commit 18a6568

Please sign in to comment.