Skip to content

Commit

Permalink
Added image_sequence capture - allows loading a set of images as a se…
Browse files Browse the repository at this point in the history
…quence
  • Loading branch information
martin-pr committed May 10, 2020
1 parent 65f94bf commit 1724d7d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 521 deletions.
6 changes: 5 additions & 1 deletion src/libs/possumwood_sdk/ui/filenames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ filenames_ui::filenames_ui() {
for(auto& p : paths)
p = possumwood::App::instance().expandPath(p.toStdString()).string().c_str();

QString parentPath = possumwood::App::instance().filename().parent_path().string().c_str();
if(paths.size() > 0)
parentPath = boost::filesystem::path(paths[0].toStdString()).parent_path().string().c_str();

// run the file dialog
paths = QFileDialog::getOpenFileNames(
possumwood::App::instance().mainWindow(),
"Select input files...",
possumwood::App::instance().filename().parent_path().string().c_str(),
parentPath,
boost::algorithm::join(m_value.extensions(), ";;").c_str()
);

Expand Down
10 changes: 5 additions & 5 deletions src/plugins/opencv/image_loading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ void copyData(ImageInput& input, cv::Mat& m) {
std::pair<cv::Mat, Exif> load(const boost::filesystem::path& filename) {
std::pair<cv::Mat, Exif> result;

if(!filename.filename().empty() && boost::filesystem::exists(filename.filename())) {
std::unique_ptr<ImageInput> in(ImageInput::open(filename.filename().string()));
if(!filename.empty() && boost::filesystem::exists(filename)) {
std::unique_ptr<ImageInput> in(ImageInput::open(filename.string()));
if (!in)
throw std::runtime_error("Error loading " + filename.filename().string());
throw std::runtime_error("Error loading " + filename.string());

// get the image spec
const ImageSpec &spec = in->spec();
Expand All @@ -72,7 +72,7 @@ std::pair<cv::Mat, Exif> load(const boost::filesystem::path& filename) {
else if(spec.format == TypeDesc::FLOAT)
copyData<float>(*in, result.first);
else
throw std::runtime_error("Error loading " + filename.filename().string() + " - only images with 8 or 32 bits per channel are supported at the moment!");
throw std::runtime_error("Error loading " + filename.string() + " - only images with 8 or 32 bits per channel are supported at the moment!");

// process metadata (EXIF)
float exposure = 0.0f;
Expand Down Expand Up @@ -103,7 +103,7 @@ std::pair<cv::Mat, Exif> load(const boost::filesystem::path& filename) {
result.second = possumwood::opencv::Exif(exposure, fnumber, iso);
}
else
throw std::runtime_error("Filename '" + filename.filename().string() + "' not found or not accessible!");
throw std::runtime_error("Filename '" + filename.string() + "' not found or not accessible!");

return result;
}
Expand Down
44 changes: 44 additions & 0 deletions src/plugins/opencv/nodes/capture/image_sequence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <possumwood_sdk/node_implementation.h>
#include <possumwood_sdk/datatypes/filenames.h>

#include <tbb/parallel_for.h>

#include <actions/traits.h>

#include "sequence.h"
#include "image_loading.h"

namespace {

dependency_graph::InAttr<possumwood::Filenames> a_filenames;
dependency_graph::OutAttr<possumwood::opencv::Sequence> a_seq;

dependency_graph::State compute(dependency_graph::Values& data) {
const auto filenames = data.get(a_filenames).filenames();

possumwood::opencv::Sequence seq(filenames.size());

tbb::parallel_for(std::size_t(0), filenames.size(), [&](std::size_t i) {
auto img = possumwood::opencv::load(filenames[i]);
seq[i] = img.first;
});

data.set(a_seq, seq);

return dependency_graph::State();
}

void init(possumwood::Metadata& meta) {
meta.addAttribute(a_filenames, "filenames", possumwood::Filenames({
"Image files (*.png *.jpg *.jpe *.jpeg *.exr *.tif *.tiff)",
}));
meta.addAttribute(a_seq, "sequence");

meta.addInfluence(a_filenames, a_seq);

meta.setCompute(compute);
}

possumwood::NodeImplementation s_impl("opencv/capture/image_sequence", init);

}
Loading

0 comments on commit 1724d7d

Please sign in to comment.