From 7f738a2db2cc120c323fb38af31977eaa14ab7ba Mon Sep 17 00:00:00 2001 From: Fabien Servant Date: Fri, 3 Mar 2023 11:34:53 +0100 Subject: [PATCH] disable compositing tiling --- .../pipeline/main_panoramaCompositing.cpp | 68 +++++++++++---- .../pipeline/main_panoramaMerging.cpp | 84 +++++++++---------- 2 files changed, 93 insertions(+), 59 deletions(-) diff --git a/src/software/pipeline/main_panoramaCompositing.cpp b/src/software/pipeline/main_panoramaCompositing.cpp index 27f12e790e..94ad2accfe 100644 --- a/src/software/pipeline/main_panoramaCompositing.cpp +++ b/src/software/pipeline/main_panoramaCompositing.cpp @@ -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& output = compositer->getOutput(); @@ -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; @@ -626,9 +637,10 @@ int aliceVision_main(int argc, char** argv) "storageDataType", po::value(&storageDataType)->default_value(storageDataType), ("Storage data type: " + image::EStorageDataType_informations()).c_str())( "rangeIteration", po::value(&rangeIteration)->default_value(rangeIteration), - "Range chunk id.")("rangeSize", po::value(&rangeSize)->default_value(rangeSize), "Range size.")( - "maxThreads", po::value(&maxThreads)->default_value(maxThreads), "max number of threads to use.")( - "labels,l", po::value(&labelsFilepath)->required(), "Labels image from seams estimation."); + "Range chunk id.")("rangeSize", po::value(&rangeSize)->default_value(rangeSize), "Range size.") + ("maxThreads", po::value(&maxThreads)->default_value(maxThreads), "max number of threads to use.") + ("labels,l", po::value(&labelsFilepath)->required(), "Labels image from seams estimation.") + ("useTiling,n", po::value(&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" @@ -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) @@ -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; } } diff --git a/src/software/pipeline/main_panoramaMerging.cpp b/src/software/pipeline/main_panoramaMerging.cpp index 277131882b..4a4100fe16 100644 --- a/src/software/pipeline/main_panoramaMerging.cpp +++ b/src/software/pipeline/main_panoramaMerging.cpp @@ -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"); @@ -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(&storageDataType)->default_value(storageDataType), ("Storage data type: " + image::EStorageDataType_informations()).c_str()); + ("storageDataType", po::value(&storageDataType)->default_value(storageDataType), ("Storage data type: " + image::EStorageDataType_informations()).c_str()) + ("useTiling,n", po::value(&useTiling)->default_value(useTiling), "use tiling for compositing."); CmdLine cmdline( "Merges all the image tiles created by the PanoramaCompositing.\n" @@ -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> 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, 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; @@ -167,7 +176,7 @@ int aliceVision_main(int argc, char** argv) if (fullTiles.find(pos) == fullTiles.end()) { - fullTiles[pos] = viewId; + fullTiles[pos] = sourceItem.first; } } } @@ -194,18 +203,9 @@ int aliceVision_main(int argc, char** argv) }; image::Image 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; @@ -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; }