mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
Merge pull request #23073 from savuor:fix_graphcut_used_edges_dense
USAC fix: GraphCut fails to allocate big dense matrices
This commit is contained in:
commit
3085fc6345
@ -53,6 +53,8 @@
|
|||||||
|
|
||||||
#include "opencv2/core/ocl.hpp"
|
#include "opencv2/core/ocl.hpp"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#define GET_OPTIMIZED(func) (func)
|
#define GET_OPTIMIZED(func) (func)
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ protected:
|
|||||||
|
|
||||||
std::vector<int> labeling_inliers;
|
std::vector<int> labeling_inliers;
|
||||||
std::vector<double> energies, weights;
|
std::vector<double> energies, weights;
|
||||||
std::vector<bool> used_edges;
|
std::set<int> used_edges;
|
||||||
std::vector<Mat> gc_models;
|
std::vector<Mat> gc_models;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ public:
|
|||||||
|
|
||||||
energies = std::vector<double>(points_size);
|
energies = std::vector<double>(points_size);
|
||||||
labeling_inliers = std::vector<int>(points_size);
|
labeling_inliers = std::vector<int>(points_size);
|
||||||
used_edges = std::vector<bool>(points_size*points_size);
|
used_edges = std::set<int>();
|
||||||
gc_models = std::vector<Mat> (estimator->getMaxNumSolutionsNonMinimal());
|
gc_models = std::vector<Mat> (estimator->getMaxNumSolutionsNonMinimal());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ private:
|
|||||||
energies[pt] = energy > 1 ? 1 : energy;
|
energies[pt] = energy > 1 ? 1 : energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fill(used_edges.begin(), used_edges.end(), false);
|
used_edges.clear();
|
||||||
|
|
||||||
bool has_edges = false;
|
bool has_edges = false;
|
||||||
// Iterate through all points and set their edges
|
// Iterate through all points and set their edges
|
||||||
@ -125,12 +125,12 @@ private:
|
|||||||
// Iterate through all neighbors
|
// Iterate through all neighbors
|
||||||
for (int actual_neighbor_idx : neighborhood_graph->getNeighbors(point_idx)) {
|
for (int actual_neighbor_idx : neighborhood_graph->getNeighbors(point_idx)) {
|
||||||
if (actual_neighbor_idx == point_idx ||
|
if (actual_neighbor_idx == point_idx ||
|
||||||
used_edges[actual_neighbor_idx*points_size + point_idx] ||
|
used_edges.count(actual_neighbor_idx*points_size + point_idx) > 0 ||
|
||||||
used_edges[point_idx*points_size + actual_neighbor_idx])
|
used_edges.count(point_idx*points_size + actual_neighbor_idx) > 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
used_edges[actual_neighbor_idx*points_size + point_idx] = true;
|
used_edges.insert(actual_neighbor_idx*points_size + point_idx);
|
||||||
used_edges[point_idx*points_size + actual_neighbor_idx] = true;
|
used_edges.insert(point_idx*points_size + actual_neighbor_idx);
|
||||||
|
|
||||||
double a = (0.5 * (energy + energies[actual_neighbor_idx])) * spatial_coherence,
|
double a = (0.5 * (energy + energies[actual_neighbor_idx])) * spatial_coherence,
|
||||||
b = spatial_coherence, c = spatial_coherence, d = 0;
|
b = spatial_coherence, c = spatial_coherence, d = 0;
|
||||||
|
@ -416,7 +416,7 @@ TEST (usac_Affine2D, accuracy) {
|
|||||||
|
|
||||||
TEST(usac_testUsacParams, accuracy) {
|
TEST(usac_testUsacParams, accuracy) {
|
||||||
std::vector<int> gt_inliers;
|
std::vector<int> gt_inliers;
|
||||||
const int pts_size = 1500;
|
const int pts_size = 150000;
|
||||||
cv::RNG &rng = cv::theRNG();
|
cv::RNG &rng = cv::theRNG();
|
||||||
const cv::UsacParams usac_params = cv::UsacParams();
|
const cv::UsacParams usac_params = cv::UsacParams();
|
||||||
cv::Mat pts1, pts2, K1, K2, mask, model, rvec, tvec, R;
|
cv::Mat pts1, pts2, K1, K2, mask, model, rvec, tvec, R;
|
||||||
|
Loading…
Reference in New Issue
Block a user