37 if (settings.
refViewNr >= mve_views.size())
38 throw std::invalid_argument(
"Master view index out of bounds");
41 if (settings.
scale < 0.f)
42 throw std::invalid_argument(
"Invalid scale factor");
46 throw std::invalid_argument(
"Invalid image embedding");
53 this->bundle = this->scene->get_bundle();
55 catch (std::exception& e)
57 throw std::runtime_error(std::string(
"Error reading bundle file: ")
62 views.resize(mve_views.size());
63 for (std::size_t i = 0; i < mve_views.size(); ++i)
65 if (mve_views[i] ==
nullptr || !mve_views[i]->is_camera_valid() ||
75 throw std::invalid_argument(
"Invalid master view");
78 refV->loadColorImage(this->settings.
scale);
79 refV->prepareMasterView(settings.
scale);
81 this->width = scaled_img->width();
82 this->height = scaled_img->height();
85 std::cout <<
"scaled image size: " << this->width <<
" x "
86 << this->height << std::endl;
97 globalViewSelection();
112 std::cout <<
"Saving ply file as "
114 << refV->createFileName(settings.
scale)
115 <<
".ply" << std::endl;
122 std::string name(
"depth-L");
124 view->set_image(refV->depthImg, name);
130 view->set_image(refV->dzImg, name);
137 view->set_image(refV->confImg, name);
140 if (settings.
scale != 0)
144 view->set_image(refV->getScaledImg()->duplicate(), name);
151 int nrPix = this->width * this->height;
152 float percent = (float) progress.
filled / (
float) nrPix;
154 std::cout <<
"Filled " << progress.
filled <<
" pixels, i.e. "
156 <<
" %." << std::endl;
160 size_t mvs_time = std::time(
nullptr) - progress.
start_time;
162 std::cout <<
"MVS took " << mvs_time <<
" seconds." << std::endl;
167 std::cout <<
"Reconstruction failed: " << e << std::endl;
179DMRecon::analyzeFeatures()
185 for (std::size_t i = 0; i < features.size() && !progress.
cancelled; ++i)
187 if (!features[i].contains_view_id(settings.
refViewNr))
191 if (!refV->pointInFrustum(featurePos))
195 this->settings.
aabbMin, this->settings.aabbMax))
198 for (std::size_t j = 0; j < features[i].refs.size(); ++j)
200 int view_id = features[i].refs[j].view_id;
201 if (view_id < 0 || view_id >=
static_cast<int>(views.size())
202 || views[view_id] ==
nullptr)
204 if (views[view_id]->pointInFrustum(featurePos))
205 views[view_id]->addFeature(i);
211DMRecon::globalViewSelection()
218 GlobalViewSelection globalVS(views, bundle->get_features(), settings);
219 globalVS.performVS();
220 neighViews = globalVS.getSelectedIDs();
222 if (neighViews.empty())
223 throw std::runtime_error(
"Global View Selection failed");
228 std::cout <<
"Global View Selection:";
229 for (IndexSet::const_iterator iter = neighViews.begin();
230 iter != neighViews.end(); ++iter)
231 std::cout <<
" " << *iter;
232 std::cout << std::endl;
237 std::cout <<
"Loading color images..." << std::endl;
238 for (IndexSet::const_iterator iter = neighViews.begin();
239 iter != neighViews.end() && !progress.
cancelled; ++iter)
240 views[*iter]->loadColorImage(0);
244DMRecon::processFeatures()
253 std::cout <<
"Processing " << features.size()
254 <<
" features..." << std::endl;
256 std::size_t success = 0;
257 std::size_t processed = 0;
258 for (std::size_t i = 0; i < features.size() && !progress.
cancelled; ++i)
264 bool useFeature =
false;
265 if (features[i].contains_view_id(settings.
refViewNr))
268 for (IndexSet::const_iterator
id = neighViews.begin();
269 useFeature ==
false &&
id != neighViews.end(); ++id)
271 if (features[i].contains_view_id(*
id))
278 if (!refV->pointInFrustum(featPos))
283 this->settings.
aabbMin, this->settings.aabbMax))
289 math::Vec2f pixPosF = refV->worldToScreenScaled(featPos);
292 float initDepth = (featPos - refV->camPos).norm();
293 PatchOptimization patch(views, settings, x, y, initDepth,
295 patch.doAutoOptimization();
296 float conf = patch.computeConfidence();
302 int const index = y * this->width + x;
303 float depth = patch.getDepth();
305 if (refV->confImg->at(index) < conf)
307 if (refV->confImg->at(index) <= 0)
310 refV->depthImg->at(index) = depth;
311 refV->normalImg->at(index, 0) = normal[0];
312 refV->normalImg->at(index, 1) = normal[1];
313 refV->normalImg->at(index, 2) = normal[2];
314 refV->dzImg->at(index, 0) = patch.getDzI();
315 refV->dzImg->at(index, 1) = patch.getDzJ();
316 refV->confImg->at(index) = conf;
318 tmpData.confidence = conf;
319 tmpData.depth = depth;
320 tmpData.dz_i = patch.getDzI();
321 tmpData.dz_j = patch.getDzJ();
322 tmpData.localViewIDs = patch.getLocalViewIDs();
325 prQueue.push(tmpData);
329 std::cout <<
"Processed " << processed <<
" features, from which "
330 << success <<
" succeeded optimization." << std::endl;
334DMRecon::processQueue()
342 std::cout <<
"Process queue ..." << std::endl;
344 size_t count = 0, lastStatus = 1;
347 std::cout <<
"Count: " << std::setw(8) << count
348 <<
" filled: " << std::setw(8) << progress.
filled
349 <<
" Queue: " << std::setw(8) << progress.
queueSize
351 lastStatus = progress.
filled;
353 while (!prQueue.empty() && !progress.
cancelled)
356 if ((progress.
filled % 1000 == 0) && (progress.
filled != lastStatus))
359 std::cout <<
"Count: " << std::setw(8) << count
360 <<
" filled: " << std::setw(8) << progress.
filled
361 <<
" Queue: " << std::setw(8) << progress.
queueSize
363 lastStatus = progress.
filled;
365 QueueData tmpData = prQueue.top();
370 int index = y * this->width + x;
371 if (refV->confImg->at(index) > tmpData.confidence) {
374 PatchOptimization patch(views, settings, x, y, tmpData.depth,
375 tmpData.dz_i, tmpData.dz_j, neighViews, tmpData.localViewIDs);
376 patch.doAutoOptimization();
377 tmpData.confidence = patch.computeConfidence();
378 if (tmpData.confidence == 0) {
382 float new_depth = patch.getDepth();
383 tmpData.depth = new_depth;
384 tmpData.dz_i = patch.getDzI();
385 tmpData.dz_j = patch.getDzJ();
387 tmpData.localViewIDs = patch.getLocalViewIDs();
388 if (refV->confImg->at(index) <= 0) {
391 if (refV->confImg->at(index) < tmpData.confidence) {
392 refV->depthImg->at(index) = tmpData.depth;
393 refV->normalImg->at(index, 0) = normal[0];
394 refV->normalImg->at(index, 1) = normal[1];
395 refV->normalImg->at(index, 2) = normal[2];
396 refV->dzImg->at(index, 0) = tmpData.dz_i;
397 refV->dzImg->at(index, 1) = tmpData.dz_j;
398 refV->confImg->at(index) = tmpData.confidence;
401 tmpData.x = x - 1; tmpData.y = y;
402 index = tmpData.y * this->width + tmpData.x;
403 if (refV->confImg->at(index) < tmpData.confidence - 0.05f ||
404 refV->confImg->at(index) == 0.f)
406 prQueue.push(tmpData);
409 tmpData.x = x + 1; tmpData.y = y;
410 index = tmpData.y * this->width + tmpData.x;
411 if (refV->confImg->at(index) < tmpData.confidence - 0.05f ||
412 refV->confImg->at(index) == 0.f)
414 prQueue.push(tmpData);
417 tmpData.x = x; tmpData.y = y - 1;
418 index = tmpData.y * this->width + tmpData.x;
419 if (refV->confImg->at(index) < tmpData.confidence - 0.05f ||
420 refV->confImg->at(index) == 0.f)
422 prQueue.push(tmpData);
425 tmpData.x = x; tmpData.y = y + 1;
426 index = tmpData.y * this->width + tmpData.x;
427 if (refV->confImg->at(index) < tmpData.confidence - 0.05f ||
428 refV->confImg->at(index) == 0.f)
430 prQueue.push(tmpData);
Vector class for arbitrary dimensions and types.
std::vector< Feature3D > Features
std::shared_ptr< Image< T > const > ConstPtr
std::shared_ptr< Scene > Ptr
std::vector< View::Ptr > ViewList
std::shared_ptr< View > Ptr
static Ptr create(mve::Scene::Ptr scene, mve::View::Ptr view, std::string const &embedding)
std::shared_ptr< SingleView const > ConstPtr
std::shared_ptr< SingleView > Ptr
Universal, simple exception class.
#define MVS_NAMESPACE_BEGIN
#define MVS_NAMESPACE_END
bool point_box_overlap(math::Vector< T, N > const &point, math::Vector< T, N > const &aabb_min, math::Vector< T, N > const &aabb_max)
Returns true if the given point overlaps with the axis-aligned box.
T round(T const &x)
Removes the fractional part of the value to the closest integer.
std::set< std::size_t > IndexSet
std::string get_fixed(T const &value, int digits)
Returns string with 'digits' of fixed precision (fills with zeros).
std::string get(T const &value)
From arbitrary types to string conversion.
std::size_t queueSize
current size of MVS pixel queue
std::size_t start_time
start time of MVS reconstruction, or 0
bool cancelled
set from extern to true to cancel reconstruction
std::size_t filled
amount of pixels with reconstructed depth value
ReconStatus status
current status of MVS algorithm
std::string imageEmbedding
Input image emebdding.
math::Vec3f aabbMin
Features outside the AABB are ignored.
std::size_t refViewNr
The reference view ID to reconstruct.