plugin  0.1.0
kuhn_munkres.hpp
1 // Copyright (C) 2018-2024 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include "opencv2/core.hpp"
8 
9 #include <memory>
10 #include <vector>
11 
12 
18 class KuhnMunkres {
19 public:
23  explicit KuhnMunkres(bool greedy = false);
24 
34  std::vector<size_t> Solve(const cv::Mat &dissimilarity_matrix);
35 
36 private:
37  static constexpr int kStar = 1;
38  static constexpr int kPrime = 2;
39 
40  cv::Mat dm_;
41  cv::Mat marked_;
42  std::vector<cv::Point> points_;
43 
44  std::vector<int> is_row_visited_;
45  std::vector<int> is_col_visited_;
46 
47  int n_;
48  bool greedy_;
49 
50  void TrySimpleCase();
51  bool CheckIfOptimumIsFound();
52  cv::Point FindUncoveredMinValPos();
53  void UpdateDissimilarityMatrix(float val);
54  int FindInRow(int row, int what);
55  int FindInCol(int col, int what);
56  void Run();
57 };
The KuhnMunkres class.
Definition: kuhn_munkres.hpp:18
std::vector< size_t > Solve(const cv::Mat &dissimilarity_matrix)
Solves the assignment problem for given dissimilarity matrix. It returns a vector that where each ele...
Definition: kuhn_munkres.cpp:13
KuhnMunkres(bool greedy=false)
Initializes the class for assignment problem solving.
Definition: kuhn_munkres.cpp:11