19 int const MIN_IMAGE_DIM = 30;
24 ImagePyramid::Ptr pyramid(
new ImagePyramid());
25 ImagePyramid& levels = *pyramid;
30 assert(proxy !=
nullptr);
32 int curr_width = proxy->
width;
33 int curr_height = proxy->
height;
35 levels.push_back(ImagePyramidLevel(cam, curr_width, curr_height));
37 while (std::min(curr_width, curr_height) >= MIN_IMAGE_DIM)
39 if (curr_width % 2 == 1)
41 / float(curr_width + 1);
42 if (curr_height % 2 == 1)
44 / float(curr_height + 1);
46 curr_width = (curr_width + 1) / 2;
47 curr_height = (curr_height + 1) / 2;
49 levels.push_back(ImagePyramidLevel(cam, curr_width, curr_height));
57 std::string embeddingName,
int minLevel)
59 if (levels[minLevel].image !=
nullptr)
63 int channels = img->channels();
66 if (channels == 2 || channels == 4)
67 mve::image::reduce_alpha<uint8_t>(img);
69 if (img->channels() == 1)
70 img = mve::image::expand_grayscale<uint8_t>(img);
72 if (img->channels() != 3)
73 throw std::invalid_argument(
"Image with invalid number of channels");
76 int curr_width = img->width();
77 int curr_height = img->height();
78 for (
int i = 0; std::min(curr_width, curr_height) >= MIN_IMAGE_DIM; ++i)
80 if (levels[i].image !=
nullptr)
85 img = mve::image::rescale_half_size_gaussian<uint8_t>(img, 1.f);
86 curr_width = img->width();
87 curr_height = img->height();
91 levels[i].image = img;
94 view->cache_cleanup();
100 std::string embeddingName,
int minLevel)
102 std::lock_guard<std::mutex> lock(ImagePyramidCache::metadataMutex);
105 if (ImagePyramidCache::cachedScene ==
nullptr)
107 ImagePyramidCache::cachedScene = scene;
108 ImagePyramidCache::cachedEmbedding = embeddingName;
113 if (scene != ImagePyramidCache::cachedScene
114 || embeddingName != ImagePyramidCache::cachedEmbedding)
117 pyramid = buildPyramid(view, embeddingName);
122 pyramid = ImagePyramidCache::entries[view->get_id()];
123 if (pyramid ==
nullptr)
125 pyramid = buildPyramid(view, embeddingName);
126 ImagePyramidCache::entries[view->get_id()] = pyramid;
130 ensureImages(*pyramid, view, embeddingName, minLevel);
135ImagePyramidCache::cleanup()
137 std::lock_guard<std::mutex> lock(ImagePyramidCache::metadataMutex);
139 if (ImagePyramidCache::cachedScene ==
nullptr)
142 for (std::map<int, ImagePyramid::Ptr>::iterator it = ImagePyramidCache::entries.begin();
143 it != ImagePyramidCache::entries.end(); ++it)
145 if (it->second ==
nullptr)
148 if (it->second.use_count() == 1)
151 ImagePyramidCache::cachedScene->get_view_by_id(it->first)->cache_cleanup();
157std::mutex ImagePyramidCache::metadataMutex;
159std::string ImagePyramidCache::cachedEmbedding =
"";
160std::map<int, ImagePyramid::Ptr> ImagePyramidCache::entries;
std::shared_ptr< Image< T > > Ptr
std::shared_ptr< Scene > Ptr
std::shared_ptr< View > Ptr
std::shared_ptr< ImagePyramid > Ptr
#define MVS_NAMESPACE_BEGIN
#define MVS_NAMESPACE_END
Per-view camera information with various helper functions.
float ppoint[2]
Principal point in x- and y-direction.