ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
MatchMatrixWidget.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "MatchMatrixWidget.h"
9 
10 #include "base/database.h"
11 #include "util/bitmap.h"
12 #include "util/option_manager.h"
13 
14 namespace cloudViewer {
15 
16 using namespace colmap;
17 
19  : ImageViewerWidget(parent), options_(options) {
20  setWindowTitle("Match matrix");
21 }
22 
24  Database database(*options_->database_path);
25 
26  if (database.NumImages() == 0) {
27  return;
28  }
29 
30  // Sort the images according to their name.
31  std::vector<Image> images = database.ReadAllImages();
32  std::sort(images.begin(), images.end(),
33  [](const Image& image1, const Image& image2) {
34  return image1.Name() < image2.Name();
35  });
36 
37  // Allocate the match matrix image.
38  Bitmap match_matrix;
39  match_matrix.Allocate(images.size(), images.size(), true);
40  match_matrix.Fill(BitmapColor<uint8_t>(255));
41 
42  // Map image identifiers to match matrix locations.
43  std::unordered_map<image_t, size_t> image_id_to_idx;
44  for (size_t idx = 0; idx < images.size(); ++idx) {
45  image_id_to_idx.emplace(images[idx].ImageId(), idx);
46  }
47 
48  std::vector<std::pair<image_t, image_t>> image_pairs;
49  std::vector<int> num_inliers;
50  database.ReadTwoViewGeometryNumInliers(&image_pairs, &num_inliers);
51 
52  // Fill the match matrix.
53  if (!num_inliers.empty()) {
54  const double max_value = std::log1p(
55  *std::max_element(num_inliers.begin(), num_inliers.end()));
56  for (size_t i = 0; i < image_pairs.size(); ++i) {
57  const double value = std::log1p(num_inliers[i]) / max_value;
58  const size_t idx1 = image_id_to_idx.at(image_pairs[i].first);
59  const size_t idx2 = image_id_to_idx.at(image_pairs[i].second);
60  const BitmapColor<float> color(255 * JetColormap::Red(value),
61  255 * JetColormap::Green(value),
62  255 * JetColormap::Blue(value));
63  match_matrix.SetPixel(idx1, idx2, color.Cast<uint8_t>());
64  match_matrix.SetPixel(idx2, idx1, color.Cast<uint8_t>());
65  }
66  }
67 
68  ShowBitmap(match_matrix);
69 }
70 
71 } // namespace cloudViewer
math::float4 color
void ShowBitmap(const colmap::Bitmap &bitmap)
MatchMatrixWidget(QWidget *parent, OptionManager *options)
Generic file read and write utility for python interface.
colmap::OptionManager OptionManager