Skip to content

Commit

Permalink
KeyframeSelection: Add support for several output extension files
Browse files Browse the repository at this point in the history
Keyframes may be written as JPG, PNG or EXR files. If the EXR format is
selected, the storage data type can be specified as well.
  • Loading branch information
cbentejac committed Jan 31, 2023
1 parent 9eca1ee commit 52d0f50
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/aliceVision/keyframe/KeyframeSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include "KeyframeSelector.hpp"
#include <aliceVision/image/all.hpp>
#include <aliceVision/sensorDB/parseDatabase.hpp>
#include <aliceVision/system/Logger.hpp>

Expand Down Expand Up @@ -370,7 +369,9 @@ bool KeyframeSelector::computeScores(const std::size_t rescaledWidth, const std:

bool KeyframeSelector::writeSelection(const std::vector<std::string>& brands,
const std::vector<std::string>& models,
const std::vector<float>& mmFocals) const
const std::vector<float>& mmFocals,
const std::string& outputExtension,
const image::EStorageDataType storageDataType) const
{
image::Image<image::RGBColor> image;
camera::PinholeRadialK3 queryIntrinsics;
Expand Down Expand Up @@ -422,7 +423,7 @@ bool KeyframeSelector::writeSelection(const std::vector<std::string>& brands,

fs::path folder = _outputFolder;
std::ostringstream filenameSS;
filenameSS << std::setw(5) << std::setfill('0') << pos << ".exr";
filenameSS << std::setw(5) << std::setfill('0') << pos << "." << outputExtension;
const auto filepath = (processedOutputFolder / fs::path(filenameSS.str())).string();

image::ImageWriteOptions options;
Expand All @@ -432,6 +433,10 @@ bool KeyframeSelector::writeSelection(const std::vector<std::string>& brands,
options.toColorSpace(image::EImageColorSpace::AUTO);
}

if (storageDataType != image::EStorageDataType::Undefined && outputExtension == "exr"){
options.storageDataType(storageDataType);
}

image::writeImage(filepath, image, options, metadata);
ALICEVISION_LOG_DEBUG("Wrote selected keyframe " << pos);
}
Expand Down
6 changes: 5 additions & 1 deletion src/aliceVision/keyframe/KeyframeSelector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include <aliceVision/dataio/FeedProvider.hpp>
#include <aliceVision/image/all.hpp>

#include <OpenImageIO/imageio.h>
#include <opencv2/optflow.hpp>
Expand Down Expand Up @@ -98,10 +99,13 @@ class KeyframeSelector
* @param[in] brands brand name for each camera
* @param[in] models model name for each camera
* @param[in] mmFocals focal in millimeters for each camera
* @param[in] outputExtension file extension of the written keyframes
* @param[in] storageDataType EXR storage data type for the output keyframes (ignored when the extension is not EXR)
* @return true if all the selected keyframes were successfully written, false otherwise
*/
bool writeSelection(const std::vector<std::string>& brands, const std::vector<std::string>& models,
const std::vector<float>& mmFocals) const;
const std::vector<float>& mmFocals, const std::string& outputExtension,
const image::EStorageDataType storageDataType = image::EStorageDataType::Undefined) const;

/**
* @brief Export the computed sharpness and optical flow scores to a CSV file
Expand Down
1 change: 1 addition & 0 deletions src/software/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ if(ALICEVISION_HAVE_OPENCV)
SOURCE main_keyframeSelection.cpp
FOLDER ${FOLDER_SOFTWARE_UTILS}
LINKS aliceVision_system
aliceVision_image
aliceVision_keyframe
${OPENIMAGEIO_LIBRARIES}
Boost::program_options
Expand Down
24 changes: 20 additions & 4 deletions src/software/utils/main_keyframeSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include <aliceVision/image/all.hpp>
#include <aliceVision/keyframe/KeyframeSelector.hpp>
#include <aliceVision/system/Logger.hpp>
#include <aliceVision/system/cmdline.hpp>
Expand All @@ -20,11 +21,13 @@
#define ALICEVISION_SOFTWARE_VERSION_MAJOR 3
#define ALICEVISION_SOFTWARE_VERSION_MINOR 0

using namespace aliceVision::keyframe;
using namespace aliceVision;

namespace po = boost::program_options;
namespace fs = boost::filesystem;

const std::string supportedExtensions = "exr, jpg, png";

int aliceVision_main(int argc, char** argv)
{
// Command-line parameters
Expand All @@ -45,6 +48,9 @@ int aliceVision_main(int argc, char** argv)
std::size_t rescaledWidth = 720; // width of the rescaled frames; 0 if no rescale is performed (smart selection)
std::size_t sharpnessWindowSize = 200; // sliding window's size in sharpness computation (smart selection)
std::size_t flowCellSize = 90; // size of the cells within a frame used to compute the optical flow (smart selection)
std::string outputExtension = "exr"; // file extension of the written keyframes
image::EStorageDataType exrDataType = // storage data type for EXR output files
image::EStorageDataType::Float;

// Debug options
bool exportScores = false; // export the sharpness and optical flow scores to a CSV file
Expand Down Expand Up @@ -79,7 +85,11 @@ int aliceVision_main(int argc, char** argv)
"\t- For the regular method, 0 = no limit. 'minFrameStep' and 'maxFrameStep' will always be respected, "
"so combining them with this parameter might cause the selection to stop before reaching the end of the "
"input sequence(s).\n"
"\t- For the smart method, the default value is set to 2000.");
"\t- For the smart method, the default value is set to 2000.")
("outputExtension", po::value<std::string>(&outputExtension)->default_value(outputExtension),
"File extension of the output keyframes.")
("storageDataType", po::value<image::EStorageDataType>(&exrDataType)->default_value(exrDataType),
("Storage data type for EXR output files: " + image::EStorageDataType_informations()).c_str());

po::options_description regularAlgorithmParams("Regular algorithm parameters");
regularAlgorithmParams.add_options()
Expand Down Expand Up @@ -160,6 +170,12 @@ int aliceVision_main(int argc, char** argv)
return EXIT_FAILURE;
}

if (supportedExtensions.find(outputExtension) == std::string::npos) {
ALICEVISION_LOG_ERROR("Unsupported extension for the output file. Supported extensions are: "
<< supportedExtensions);
return EXIT_FAILURE;
}

brands.resize(nbCameras);
models.resize(nbCameras);
mmFocals.resize(nbCameras);
Expand All @@ -180,7 +196,7 @@ int aliceVision_main(int argc, char** argv)
}

// Initialize KeyframeSelector
KeyframeSelector selector(mediaPaths, sensorDbPath, outputFolder);
keyframe::KeyframeSelector selector(mediaPaths, sensorDbPath, outputFolder);

// Set frame-related algorithm parameters
selector.setMinFrameStep(minFrameStep);
Expand Down Expand Up @@ -213,7 +229,7 @@ int aliceVision_main(int argc, char** argv)
selector.processRegular();

// Write selected keyframes
selector.writeSelection(brands, models, mmFocals);
selector.writeSelection(brands, models, mmFocals, outputExtension, exrDataType);

// If debug options are set, export the scores as a CSV file and / or the motion vectors as images
if (exportScores)
Expand Down

0 comments on commit 52d0f50

Please sign in to comment.