ImageExtractor.cpp
Go to the documentation of this file.
1#include "ImageExtractor.h"
2
4{
5 void
7 {
9
11 for (const auto& [key, child] : dict->getElements())
12 {
13 if (child && child->getDescriptor() == aron::data::Descriptor::NDARRAY)
14 {
15 auto ndarray = aron::data::NDArray::DynamicCastAndCheck(child);
16 auto shape = ndarray->getShape();
17 if (shape.size() == 3 &&
18 (shape[2] == 3 || shape[2] == 1 /* 3 channel color or grayscale */) &&
19 std::accumulate(std::begin(shape), std::end(shape), 1, std::multiplies<int>()) >
20 200) // must be big enough to assume an image (instead of 4x4x4 poses)
21 {
22 images[key] = ndarray;
23 dict->setElement(key, nullptr);
24 }
25 }
26 }
27 }
28
29 void
31 {
32 // A member is null. Simply ignore...
33 }
34
37 {
39 aron::data::VariantPtr var = std::static_pointer_cast<aron::data::Variant>(data);
41 aron::data::visitRecursive(visitor, var);
42
43 ExtractionResult encoding;
44 encoding.dataWithoutExtraction = data;
45 encoding.extraction = visitor.images;
46 return encoding;
47 }
48
51 {
52 return encoding.dataWithoutExtraction;
53 }
54} // namespace armarx::armem::server::ltm::processor::extractor
aron::data::DictPtr merge(ExtractionResult &encoding) override
ExtractionResult extract(aron::data::DictPtr &data) override
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
std::shared_ptr< Variant > VariantPtr
void visitRecursive(RecursiveVisitorImplementation &v, typename RecursiveVisitorImplementation::Input &o)
std::map< std::string, aron::data::VariantPtr > extraction
Definition Extractor.h:21
typename VisitorBase< data::VariantPtr >::Input Input