Fixed some errors in test data for eigen. Added test using lowindex & highindex in eigen function.
This commit is contained in:
parent
ec7bc9e497
commit
1767049f30
@ -3,6 +3,8 @@
|
|||||||
using namespace cv;
|
using namespace cv;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
#define sign(a) a > 0 ? 1 : a < 0 ? 0 : -1
|
||||||
|
|
||||||
class Core_EigenTest: public cvtest::BaseTest
|
class Core_EigenTest: public cvtest::BaseTest
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -12,13 +14,12 @@ class Core_EigenTest: public cvtest::BaseTest
|
|||||||
protected:
|
protected:
|
||||||
void run (int);
|
void run (int);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
float eps_val_32, eps_vec_32;
|
float eps_val_32, eps_vec_32;
|
||||||
double eps_val_64, eps_vec_64;
|
double eps_val_64, eps_vec_64;
|
||||||
void check_pair_count(const cv::Mat& src, const cv::Mat& evalues);
|
void check_pair_count(const cv::Mat& src, const cv::Mat& evalues, int low_index = -1, int high_index = -1);
|
||||||
void check_pair_count(const cv::Mat& src, const cv::Mat& evalues, const cv::Mat& evectors);
|
void check_pair_count(const cv::Mat& src, const cv::Mat& evalues, const cv::Mat& evectors, int low_index = -1, int high_index = -1);
|
||||||
bool check_diff(const cv::Mat& original_values, const cv::Mat& original_vectors,
|
bool check_diff(const cv::Mat& original_values, const cv::Mat& original_vectors,
|
||||||
const cv::Mat& found_values, const cv::Mat& found_vectors,
|
const cv::Mat& found_values, const cv::Mat& found_vectors,
|
||||||
const bool compute_eigen_vectors, const int values_type, const int norm_type);
|
const bool compute_eigen_vectors, const int values_type, const int norm_type);
|
||||||
@ -27,14 +28,20 @@ class Core_EigenTest: public cvtest::BaseTest
|
|||||||
Core_EigenTest::Core_EigenTest() : eps_val_32(1e-6), eps_vec_32(1e-5), eps_val_64(1e-12), eps_vec_64(1e-11) {}
|
Core_EigenTest::Core_EigenTest() : eps_val_32(1e-6), eps_vec_32(1e-5), eps_val_64(1e-12), eps_vec_64(1e-11) {}
|
||||||
Core_EigenTest::~Core_EigenTest() {}
|
Core_EigenTest::~Core_EigenTest() {}
|
||||||
|
|
||||||
void Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues)
|
void Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues, int low_index, int high_index)
|
||||||
{
|
{
|
||||||
CV_Assert(src.rows == evalues.rows && evalues.cols == 1);
|
int n = src.rows, s = sign(high_index);
|
||||||
|
CV_Assert(evalues.rows == n - (low_index+1) - ((int)((n/2.0)*(s*s-s)) + (1+s-s*s)*(n - (high_index+1))) && evalues.cols == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues, const cv::Mat& evectors)
|
void Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues, const cv::Mat& evectors, int low_index, int high_index)
|
||||||
{
|
{
|
||||||
CV_Assert( src.rows == evectors.rows && src.cols == evectors.cols && src.rows == evalues.rows && evalues.cols == 1);
|
int n = src.rows, s = sign(high_index);
|
||||||
|
int right_eigen_pair_count = n - (low_index+1) - ((int)((n/2.0)*(s*s-s)) + (1+s-s*s)*(n - (high_index+1)));
|
||||||
|
CV_Assert( evectors.rows == right_eigen_pair_count &&
|
||||||
|
evectors.cols == right_eigen_pair_count &&
|
||||||
|
evalues.rows == right_eigen_pair_count &&
|
||||||
|
evalues.cols == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Core_EigenTest::check_diff(const cv::Mat& original_values, const cv::Mat& original_vectors,
|
bool Core_EigenTest::check_diff(const cv::Mat& original_values, const cv::Mat& original_vectors,
|
||||||
@ -50,7 +57,7 @@ bool Core_EigenTest::check_diff(const cv::Mat& original_values, const cv::Mat& o
|
|||||||
{
|
{
|
||||||
double diff_val = cv::norm(original_values, found_values, norm_type);
|
double diff_val = cv::norm(original_values, found_values, norm_type);
|
||||||
double diff_vec = cv::norm(original_vectors, found_vectors, norm_type);
|
double diff_vec = cv::norm(original_vectors, found_vectors, norm_type);
|
||||||
|
|
||||||
if (diff_val > eps_val) { ts->printf(cvtest::TS::LOG, "Accuracy of eigen values computing less than requered."); return false; }
|
if (diff_val > eps_val) { ts->printf(cvtest::TS::LOG, "Accuracy of eigen values computing less than requered."); return false; }
|
||||||
if (diff_vec > eps_vec) { ts->printf(cvtest::TS::LOG, "Accuracy of eigen vectors computing less than requered."); return false; }
|
if (diff_vec > eps_vec) { ts->printf(cvtest::TS::LOG, "Accuracy of eigen vectors computing less than requered."); return false; }
|
||||||
|
|
||||||
@ -75,20 +82,18 @@ bool Core_EigenTest::check_diff(const cv::Mat& original_values, const cv::Mat& o
|
|||||||
void Core_EigenTest::run(int)
|
void Core_EigenTest::run(int)
|
||||||
{
|
{
|
||||||
const int DIM = 3;
|
const int DIM = 3;
|
||||||
|
|
||||||
bool ok = true;
|
|
||||||
|
|
||||||
// tests data
|
// tests data
|
||||||
|
|
||||||
float sym_matrix[DIM][DIM] = { { 0.0f, 1.0f, 0.0f },
|
float sym_matrix[DIM][DIM] = { { 0.0f, 1.0f, 0.0f },
|
||||||
{ 1.0f, 0.0f, 1.0f },
|
{ 1.0f, 0.0f, 1.0f },
|
||||||
{ 0.0f, 1.0f, 0.0f } }; // source symmerical matrix
|
{ 0.0f, 1.0f, 0.0f } }; // source symmerical matrix
|
||||||
|
|
||||||
float _eval[DIM] = { 0.5f*sqrt(2.0f), 0.0f, -0.5f*sqrt(2.0f) }; // eigen values of 3*3 matrix
|
float _eval[DIM] = { sqrt(2.0f), 0.0f, -sqrt(2.0f) }; // eigen values of 3*3 matrix
|
||||||
|
|
||||||
float _evec[DIM][DIM] = { { 0.5f, -1.0f, 0.5f },
|
float _evec[DIM][DIM] = { { 1.0f, sqrt(2.0f), 1.0f },
|
||||||
{ 0.5f*sqrt(2.0f), 0.0f, -0.5f*sqrt(2.0f) },
|
{ -1.0f, 0.0f, 1.0f },
|
||||||
{ 0.5f, 1.0f, 0.5f } }; // eigen vectors of source matrix
|
{ 1.0f, -sqrt(2.0f), 1.0f } }; // eigen vectors of source matrix
|
||||||
|
|
||||||
// initializing Mat-objects
|
// initializing Mat-objects
|
||||||
|
|
||||||
@ -100,6 +105,8 @@ void Core_EigenTest::run(int)
|
|||||||
|
|
||||||
cv::eigen(src_32, true, eigen_values, eigen_vectors);
|
cv::eigen(src_32, true, eigen_values, eigen_vectors);
|
||||||
|
|
||||||
|
check_pair_count(src_32, eigen_values, eigen_vectors);
|
||||||
|
|
||||||
if (!check_diff(eval_32, evec_32, eigen_values, eigen_vectors, true, CV_32FC1, NORM_L1)) return;
|
if (!check_diff(eval_32, evec_32, eigen_values, eigen_vectors, true, CV_32FC1, NORM_L1)) return;
|
||||||
if (!check_diff(eval_32, evec_32, eigen_values, eigen_vectors, true, CV_32FC1, NORM_L2)) return;
|
if (!check_diff(eval_32, evec_32, eigen_values, eigen_vectors, true, CV_32FC1, NORM_L2)) return;
|
||||||
if (!check_diff(eval_32, evec_32, eigen_values, eigen_vectors, true, CV_32FC1, NORM_INF)) return;
|
if (!check_diff(eval_32, evec_32, eigen_values, eigen_vectors, true, CV_32FC1, NORM_INF)) return;
|
||||||
@ -161,6 +168,45 @@ void Core_EigenTest::run(int)
|
|||||||
if (!check_diff(eval_64, evec_64, eigen_values, eigen_vectors, false, CV_64FC1, NORM_L1)) return;
|
if (!check_diff(eval_64, evec_64, eigen_values, eigen_vectors, false, CV_64FC1, NORM_L1)) return;
|
||||||
if (!check_diff(eval_64, evec_64, eigen_values, eigen_vectors, false, CV_64FC1, NORM_L2)) return;
|
if (!check_diff(eval_64, evec_64, eigen_values, eigen_vectors, false, CV_64FC1, NORM_L2)) return;
|
||||||
if (!check_diff(eval_64, evec_64, eigen_values, eigen_vectors, false, CV_64FC1, NORM_INF)) return;
|
if (!check_diff(eval_64, evec_64, eigen_values, eigen_vectors, false, CV_64FC1, NORM_INF)) return;
|
||||||
|
|
||||||
|
const int low_index = 2, high_index = 3;
|
||||||
|
cv::Mat submat_val_32(eval_32.rowRange(low_index, high_index));
|
||||||
|
cv::Mat submat_vec_32(evec_32.rowRange(low_index, high_index));
|
||||||
|
|
||||||
|
cv::eigen(src_32, eigen_values, low_index, high_index);
|
||||||
|
|
||||||
|
check_pair_count(src_32, eigen_values, eigen_vectors, low_index, high_index);
|
||||||
|
|
||||||
|
if (!check_diff(submat_val_32, submat_vec_32, eigen_values, eigen_vectors, false, CV_32FC1, NORM_L1)) return;
|
||||||
|
if (!check_diff(submat_val_32, submat_vec_32, eigen_values, eigen_vectors, false, CV_32FC1, NORM_L2)) return;
|
||||||
|
if (!check_diff(submat_val_32, submat_vec_32, eigen_values, eigen_vectors, false, CV_32FC1, NORM_INF)) return;
|
||||||
|
|
||||||
|
cv::eigen(src_32, eigen_values, eigen_vectors, low_index, high_index);
|
||||||
|
|
||||||
|
check_pair_count(src_32, eigen_values, eigen_vectors, low_index, high_index);
|
||||||
|
|
||||||
|
if (!check_diff(submat_val_32, submat_vec_32, eigen_values, eigen_vectors, true, CV_32FC1, NORM_L1)) return;
|
||||||
|
if (!check_diff(submat_val_32, submat_vec_32, eigen_values, eigen_vectors, true, CV_32FC1, NORM_L2)) return;
|
||||||
|
if (!check_diff(submat_val_32, submat_vec_32, eigen_values, eigen_vectors, true, CV_32FC1, NORM_INF)) return;
|
||||||
|
|
||||||
|
cv::Mat submat_val_64(eval_64.rowRange(low_index, high_index));
|
||||||
|
cv::Mat submat_vec_64(evec_64.rowRange(low_index, high_index));
|
||||||
|
|
||||||
|
cv::eigen(src_64, eigen_values, low_index, high_index);
|
||||||
|
|
||||||
|
check_pair_count(src_64, eigen_values, low_index, high_index);
|
||||||
|
|
||||||
|
if (!check_diff(submat_val_64, submat_vec_64, eigen_values, eigen_vectors, false, CV_64FC1, NORM_L1)) return;
|
||||||
|
if (!check_diff(submat_val_64, submat_vec_64, eigen_values, eigen_vectors, false, CV_64FC1, NORM_L2)) return;
|
||||||
|
if (!check_diff(submat_val_64, submat_vec_64, eigen_values, eigen_vectors, false, CV_64FC1, NORM_INF)) return;
|
||||||
|
|
||||||
|
cv::eigen(src_64, eigen_values, eigen_vectors, low_index, high_index);
|
||||||
|
|
||||||
|
check_pair_count(src_64, eigen_values, low_index, high_index);
|
||||||
|
|
||||||
|
if (!check_diff(submat_val_64, submat_vec_64, eigen_values, eigen_vectors, true, CV_64FC1, NORM_L1)) return;
|
||||||
|
if (!check_diff(submat_val_64, submat_vec_64, eigen_values, eigen_vectors, true, CV_64FC1, NORM_L2)) return;
|
||||||
|
if (!check_diff(submat_val_64, submat_vec_64, eigen_values, eigen_vectors, true, CV_64FC1, NORM_INF)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Core_Eigen, quality) { Core_EigenTest test; test.safe_run(); }
|
TEST(Core_Eigen, quality) { Core_EigenTest test; test.safe_run(); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user