mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge branch 4.x
This commit is contained in:
Regular → Executable
@@ -20,7 +20,7 @@ protected:
|
||||
|
||||
std::vector<int> labeling_inliers;
|
||||
std::vector<double> energies, weights;
|
||||
std::vector<bool> used_edges;
|
||||
std::set<int> used_edges;
|
||||
std::vector<Mat> gc_models;
|
||||
public:
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
|
||||
energies = std::vector<double>(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());
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ private:
|
||||
energies[pt] = energy > 1 ? 1 : energy;
|
||||
}
|
||||
|
||||
std::fill(used_edges.begin(), used_edges.end(), false);
|
||||
used_edges.clear();
|
||||
|
||||
bool has_edges = false;
|
||||
// Iterate through all points and set their edges
|
||||
@@ -125,12 +125,12 @@ private:
|
||||
// Iterate through all neighbors
|
||||
for (int actual_neighbor_idx : neighborhood_graph->getNeighbors(point_idx)) {
|
||||
if (actual_neighbor_idx == point_idx ||
|
||||
used_edges[actual_neighbor_idx*points_size + point_idx] ||
|
||||
used_edges[point_idx*points_size + actual_neighbor_idx])
|
||||
used_edges.count(actual_neighbor_idx*points_size + point_idx) > 0 ||
|
||||
used_edges.count(point_idx*points_size + actual_neighbor_idx) > 0)
|
||||
continue;
|
||||
|
||||
used_edges[actual_neighbor_idx*points_size + point_idx] = true;
|
||||
used_edges[point_idx*points_size + actual_neighbor_idx] = true;
|
||||
used_edges.insert(actual_neighbor_idx*points_size + point_idx);
|
||||
used_edges.insert(point_idx*points_size + actual_neighbor_idx);
|
||||
|
||||
double a = (0.5 * (energy + energies[actual_neighbor_idx])) * spatial_coherence,
|
||||
b = spatial_coherence, c = spatial_coherence, d = 0;
|
||||
|
||||
@@ -74,60 +74,27 @@ int METHOD[METHODS_COUNT] = {0, cv::RANSAC, cv::LMEDS, cv::RHO};
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
class CV_HomographyTest: public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_HomographyTest();
|
||||
~CV_HomographyTest();
|
||||
|
||||
void run (int);
|
||||
namespace HomographyTestUtils {
|
||||
|
||||
protected:
|
||||
static const float max_diff = 0.032f;
|
||||
static const float max_2diff = 0.020f;
|
||||
static const int image_size = 100;
|
||||
static const double reproj_threshold = 3.0;
|
||||
static const double sigma = 0.01;
|
||||
|
||||
int method;
|
||||
int image_size;
|
||||
double reproj_threshold;
|
||||
double sigma;
|
||||
|
||||
private:
|
||||
float max_diff, max_2diff;
|
||||
bool check_matrix_size(const cv::Mat& H);
|
||||
bool check_matrix_diff(const cv::Mat& original, const cv::Mat& found, const int norm_type, double &diff);
|
||||
int check_ransac_mask_1(const Mat& src, const Mat& mask);
|
||||
int check_ransac_mask_2(const Mat& original_mask, const Mat& found_mask);
|
||||
|
||||
void print_information_1(int j, int N, int method, const Mat& H);
|
||||
void print_information_2(int j, int N, int method, const Mat& H, const Mat& H_res, int k, double diff);
|
||||
void print_information_3(int method, int j, int N, const Mat& mask);
|
||||
void print_information_4(int method, int j, int N, int k, int l, double diff);
|
||||
void print_information_5(int method, int j, int N, int l, double diff);
|
||||
void print_information_6(int method, int j, int N, int k, double diff, bool value);
|
||||
void print_information_7(int method, int j, int N, int k, double diff, bool original_value, bool found_value);
|
||||
void print_information_8(int method, int j, int N, int k, int l, double diff);
|
||||
};
|
||||
|
||||
CV_HomographyTest::CV_HomographyTest() : max_diff(1e-2f), max_2diff(2e-2f)
|
||||
{
|
||||
method = 0;
|
||||
image_size = 100;
|
||||
reproj_threshold = 3.0;
|
||||
sigma = 0.01;
|
||||
}
|
||||
|
||||
CV_HomographyTest::~CV_HomographyTest() {}
|
||||
|
||||
bool CV_HomographyTest::check_matrix_size(const cv::Mat& H)
|
||||
static bool check_matrix_size(const cv::Mat& H)
|
||||
{
|
||||
return (H.rows == 3) && (H.cols == 3);
|
||||
}
|
||||
|
||||
bool CV_HomographyTest::check_matrix_diff(const cv::Mat& original, const cv::Mat& found, const int norm_type, double &diff)
|
||||
static bool check_matrix_diff(const cv::Mat& original, const cv::Mat& found, const int norm_type, double &diff)
|
||||
{
|
||||
diff = cvtest::norm(original, found, norm_type);
|
||||
return diff <= max_diff;
|
||||
}
|
||||
|
||||
int CV_HomographyTest::check_ransac_mask_1(const Mat& src, const Mat& mask)
|
||||
static int check_ransac_mask_1(const Mat& src, const Mat& mask)
|
||||
{
|
||||
if (!(mask.cols == 1) && (mask.rows == src.cols)) return 1;
|
||||
if (countNonZero(mask) < mask.rows) return 2;
|
||||
@@ -135,14 +102,14 @@ int CV_HomographyTest::check_ransac_mask_1(const Mat& src, const Mat& mask)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CV_HomographyTest::check_ransac_mask_2(const Mat& original_mask, const Mat& found_mask)
|
||||
static int check_ransac_mask_2(const Mat& original_mask, const Mat& found_mask)
|
||||
{
|
||||
if (!(found_mask.cols == 1) && (found_mask.rows == original_mask.rows)) return 1;
|
||||
for (int i = 0; i < found_mask.rows; ++i) if (found_mask.at<uchar>(i, 0) > 1) return 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::print_information_1(int j, int N, int _method, const Mat& H)
|
||||
static void print_information_1(int j, int N, int _method, const Mat& H)
|
||||
{
|
||||
cout << endl; cout << "Checking for homography matrix sizes..." << endl; cout << endl;
|
||||
cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";
|
||||
@@ -154,7 +121,7 @@ void CV_HomographyTest::print_information_1(int j, int N, int _method, const Mat
|
||||
cout << "Number of rows: " << H.rows << " Number of cols: " << H.cols << endl; cout << endl;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::print_information_2(int j, int N, int _method, const Mat& H, const Mat& H_res, int k, double diff)
|
||||
static void print_information_2(int j, int N, int _method, const Mat& H, const Mat& H_res, int k, double diff)
|
||||
{
|
||||
cout << endl; cout << "Checking for accuracy of homography matrix computing..." << endl; cout << endl;
|
||||
cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";
|
||||
@@ -170,7 +137,7 @@ void CV_HomographyTest::print_information_2(int j, int N, int _method, const Mat
|
||||
cout << "Maximum allowed difference: " << max_diff << endl; cout << endl;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::print_information_3(int _method, int j, int N, const Mat& mask)
|
||||
static void print_information_3(int _method, int j, int N, const Mat& mask)
|
||||
{
|
||||
cout << endl; cout << "Checking for inliers/outliers mask..." << endl; cout << endl;
|
||||
cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";
|
||||
@@ -182,7 +149,7 @@ void CV_HomographyTest::print_information_3(int _method, int j, int N, const Mat
|
||||
cout << "Number of rows: " << mask.rows << " Number of cols: " << mask.cols << endl; cout << endl;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::print_information_4(int _method, int j, int N, int k, int l, double diff)
|
||||
static void print_information_4(int _method, int j, int N, int k, int l, double diff)
|
||||
{
|
||||
cout << endl; cout << "Checking for accuracy of reprojection error computing..." << endl; cout << endl;
|
||||
cout << "Method: "; if (_method == 0) cout << 0 << endl; else cout << "CV_LMEDS" << endl;
|
||||
@@ -196,7 +163,7 @@ void CV_HomographyTest::print_information_4(int _method, int j, int N, int k, in
|
||||
cout << "Maximum allowed difference: " << max_2diff << endl; cout << endl;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::print_information_5(int _method, int j, int N, int l, double diff)
|
||||
static void print_information_5(int _method, int j, int N, int l, double diff)
|
||||
{
|
||||
cout << endl; cout << "Checking for accuracy of reprojection error computing..." << endl; cout << endl;
|
||||
cout << "Method: "; if (_method == 0) cout << 0 << endl; else cout << "CV_LMEDS" << endl;
|
||||
@@ -209,7 +176,7 @@ void CV_HomographyTest::print_information_5(int _method, int j, int N, int l, do
|
||||
cout << "Maximum allowed difference: " << max_diff << endl; cout << endl;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::print_information_6(int _method, int j, int N, int k, double diff, bool value)
|
||||
static void print_information_6(int _method, int j, int N, int k, double diff, bool value)
|
||||
{
|
||||
cout << endl; cout << "Checking for inliers/outliers mask..." << endl; cout << endl;
|
||||
cout << "Method: "; if (_method == RANSAC) cout << "RANSAC" << endl; else if (_method == cv::RHO) cout << "RHO" << endl; else cout << _method << endl;
|
||||
@@ -222,7 +189,7 @@ void CV_HomographyTest::print_information_6(int _method, int j, int N, int k, do
|
||||
cout << "Value of found mask: "<< value << endl; cout << endl;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::print_information_7(int _method, int j, int N, int k, double diff, bool original_value, bool found_value)
|
||||
static void print_information_7(int _method, int j, int N, int k, double diff, bool original_value, bool found_value)
|
||||
{
|
||||
cout << endl; cout << "Checking for inliers/outliers mask..." << endl; cout << endl;
|
||||
cout << "Method: "; if (_method == RANSAC) cout << "RANSAC" << endl; else if (_method == cv::RHO) cout << "RHO" << endl; else cout << _method << endl;
|
||||
@@ -235,7 +202,7 @@ void CV_HomographyTest::print_information_7(int _method, int j, int N, int k, do
|
||||
cout << "Value of original mask: "<< original_value << " Value of found mask: " << found_value << endl; cout << endl;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::print_information_8(int _method, int j, int N, int k, int l, double diff)
|
||||
static void print_information_8(int _method, int j, int N, int k, int l, double diff)
|
||||
{
|
||||
cout << endl; cout << "Checking for reprojection error of inlier..." << endl; cout << endl;
|
||||
cout << "Method: "; if (_method == RANSAC) cout << "RANSAC" << endl; else if (_method == cv::RHO) cout << "RHO" << endl; else cout << _method << endl;
|
||||
@@ -249,11 +216,15 @@ void CV_HomographyTest::print_information_8(int _method, int j, int N, int k, in
|
||||
cout << "Maximum allowed difference: " << max_2diff << endl; cout << endl;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::run(int)
|
||||
} // HomographyTestUtils::
|
||||
|
||||
|
||||
TEST(Calib3d_Homography, accuracy)
|
||||
{
|
||||
using namespace HomographyTestUtils;
|
||||
for (int N = MIN_COUNT_OF_POINTS; N <= MAX_COUNT_OF_POINTS; ++N)
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
RNG& rng = cv::theRNG();
|
||||
|
||||
float *src_data = new float [2*N];
|
||||
|
||||
@@ -309,7 +280,7 @@ void CV_HomographyTest::run(int)
|
||||
|
||||
for (int i = 0; i < METHODS_COUNT; ++i)
|
||||
{
|
||||
method = METHOD[i];
|
||||
const int method = METHOD[i];
|
||||
switch (method)
|
||||
{
|
||||
case 0:
|
||||
@@ -412,7 +383,7 @@ void CV_HomographyTest::run(int)
|
||||
|
||||
for (int i = 0; i < METHODS_COUNT; ++i)
|
||||
{
|
||||
method = METHOD[i];
|
||||
const int method = METHOD[i];
|
||||
switch (method)
|
||||
{
|
||||
case 0:
|
||||
@@ -574,8 +545,6 @@ void CV_HomographyTest::run(int)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Calib3d_Homography, accuracy) { CV_HomographyTest test; test.safe_run(); }
|
||||
|
||||
TEST(Calib3d_Homography, EKcase)
|
||||
{
|
||||
float pt1data[] =
|
||||
|
||||
@@ -416,7 +416,7 @@ TEST (usac_Affine2D, accuracy) {
|
||||
|
||||
TEST(usac_testUsacParams, accuracy) {
|
||||
std::vector<int> gt_inliers;
|
||||
const int pts_size = 1500;
|
||||
const int pts_size = 150000;
|
||||
cv::RNG &rng = cv::theRNG();
|
||||
const cv::UsacParams usac_params = cv::UsacParams();
|
||||
cv::Mat pts1, pts2, K1, K2, mask, model, rvec, tvec, R;
|
||||
|
||||
Reference in New Issue
Block a user