\r
class CV_HomographyTest: public cvtest::ArrayTest\r
{\r
- public:\r
- \r
- CV_HomographyTest();\r
- ~CV_HomographyTest();\r
-\r
- int read_params( CvFileStorage* fs );\r
- void fill_array( int test_case_idx, int i, int j, Mat& arr );\r
- int prepare_test_case( int test_case_idx );\r
- void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );\r
- void run (int);\r
-\r
- bool check_matrix (const Mat& H);\r
- bool check_transform (const Mat& src, const Mat& dst, const Mat& H);\r
- \r
-\r
- void prepare_to_validation( int test_case_idx );\r
-\r
- protected:\r
-\r
- int method;\r
- int image_size;\r
- int square_size;\r
- double reproj_threshold;\r
- double sigma;\r
- bool test_cpp;\r
- \r
- double get_success_error_level( int test_case_idx, int i, int j );\r
- void test_projectPoints(Mat& src_2d, Mat& dst_2d, const Mat& H, RNG* rng, double sigma); // checking for quality of perpective transformation\r
- \r
- private:\r
+public:\r
+ CV_HomographyTest();\r
+ ~CV_HomographyTest();\r
+\r
+ void run (int);\r
+\r
+protected:\r
+\r
+ int method;\r
+ int image_size;\r
+ double reproj_threshold;\r
+ double sigma;\r
+\r
+private:\r
float max_diff, max_2diff;\r
bool check_matrix_size(const cv::Mat& H);\r
bool check_matrix_diff(const cv::Mat& original, const cv::Mat& found, const int norm_type, double &diff);\r
- // bool check_reproj_error(const cv::Mat& src_3d, const cv::Mat& dst_3d, const int norm_type = NORM_L2);\r
- int check_ransac_mask_1(const Mat& src, const Mat& mask);\r
+ int check_ransac_mask_1(const Mat& src, const Mat& mask);\r
int check_ransac_mask_2(const Mat& original_mask, const Mat& found_mask);\r
\r
void print_information_1(int j, int N, int method, const Mat& H);\r
void print_information_6(int j, int N, int k, double diff, bool value);\r
void print_information_7(int j, int N, int k, double diff, bool original_value, bool found_value);\r
void print_information_8(int j, int N, int k, int l, double diff);\r
-\r
- void check_transform_quality(cv::InputArray src_points, cv::InputArray dst_poits, const cv::Mat& H, const int norm_type = NORM_L2);\r
- void check_transform_quality(const cv::InputArray src_points, const vector <cv::Point2f> dst_points, const cv::Mat& H, const int norm_type = NORM_L2);\r
- void check_transform_quality(const vector <cv::Point2f> src_points, const cv::InputArray dst_points, const cv::Mat& H, const int norm_type = NORM_L2); \r
- void check_transform_quality(const vector <cv::Point2f> src_points, const vector <cv::Point2f> dst_points, const cv::Mat& H, const int norm_type = NORM_L2);\r
};\r
\r
CV_HomographyTest::CV_HomographyTest() : max_diff(1e-2), max_2diff(2e-2)\r
{\r
- test_array[INPUT].push_back(NULL);\r
- test_array[INPUT].push_back(NULL);\r
- test_array[INPUT].push_back(NULL);\r
- test_array[INPUT].push_back(NULL);\r
- test_array[INPUT].push_back(NULL);\r
- test_array[INPUT].push_back(NULL);\r
- test_array[TEMP].push_back(NULL);\r
- test_array[TEMP].push_back(NULL);\r
- test_array[OUTPUT].push_back(NULL);\r
- test_array[OUTPUT].push_back(NULL);\r
- test_array[REF_OUTPUT].push_back(NULL);\r
- test_array[REF_OUTPUT].push_back(NULL);\r
-\r
- element_wise_relative_error = false;\r
-\r
- method = 0;\r
- image_size = 1e+2;\r
- reproj_threshold = 3.0;\r
- sigma = 0.01;\r
-\r
- test_cpp = false;\r
+ method = 0;\r
+ image_size = 1e+2;\r
+ reproj_threshold = 3.0;\r
+ sigma = 0.01;\r
}\r
\r
CV_HomographyTest::~CV_HomographyTest() {}\r
\r
-void CV_HomographyTest::get_test_array_types_and_sizes( int /*test_case_idx*/, vector<vector<Size> >& sizes, vector<vector<int> >& types )\r
+bool CV_HomographyTest::check_matrix_size(const cv::Mat& H) \r
{\r
- RNG& rng = ts->get_rng();\r
- int pt_depth = CV_32F;\r
- double pt_count_exp = cvtest::randReal(rng)*6 + 1;\r
- int pt_count = cvRound(exp(pt_count_exp));\r
-\r
- /* dims = cvtest::randInt(rng) % 2 + 2;\r
- method = 1 << (cvtest::randInt(rng) % 4);\r
-\r
- if( method == CV_FM_7POINT )\r
- pt_count = 7;\r
- else\r
- {\r
- pt_count = MAX( pt_count, 8 + (method == CV_FM_8POINT) );\r
- if( pt_count >= 8 && cvtest::randInt(rng) % 2 )\r
- method |= CV_FM_8POINT;\r
- } */\r
-\r
- types[INPUT][0] = CV_MAKETYPE(pt_depth, 2);\r
- \r
- types[INPUT][1] = types[INPUT][0];\r
-\r
- types[OUTPUT][0] = CV_MAKETYPE(pt_depth, 1);\r
- \r
- /* if( cvtest::randInt(rng) % 2 )\r
- sizes[INPUT][0] = cvSize(pt_count, dims);\r
- else\r
- {\r
- sizes[INPUT][0] = cvSize(dims, pt_count);\r
- if( cvtest::randInt(rng) % 2 )\r
- {\r
- types[INPUT][0] = CV_MAKETYPE(pt_depth, dims);\r
- if( cvtest::randInt(rng) % 2 )\r
- sizes[INPUT][0] = cvSize(pt_count, 1);\r
- else\r
- sizes[INPUT][0] = cvSize(1, pt_count);\r
- }\r
- }\r
-\r
- sizes[INPUT][1] = sizes[INPUT][0];\r
- types[INPUT][1] = types[INPUT][0];\r
-\r
- sizes[INPUT][2] = cvSize(pt_count, 1 );\r
- types[INPUT][2] = CV_64FC3;\r
-\r
- sizes[INPUT][3] = cvSize(4,3);\r
- types[INPUT][3] = CV_64FC1;\r
+ return (H.rows == 3) && (H.cols == 3);\r
+}\r
\r
- sizes[INPUT][4] = sizes[INPUT][5] = cvSize(3,3);\r
- types[INPUT][4] = types[INPUT][5] = CV_MAKETYPE(CV_64F, 1);\r
+bool CV_HomographyTest::check_matrix_diff(const cv::Mat& original, const cv::Mat& found, const int norm_type, double &diff)\r
+{\r
+ diff = cv::norm(original, found, norm_type);\r
+ return diff <= max_diff;\r
+}\r
\r
- sizes[TEMP][0] = cvSize(3,3);\r
- types[TEMP][0] = CV_64FC1;\r
- sizes[TEMP][1] = cvSize(pt_count,1);\r
- types[TEMP][1] = CV_8UC1;\r
+int CV_HomographyTest::check_ransac_mask_1(const Mat& src, const Mat& mask)\r
+{\r
+ if (!(mask.cols == 1) && (mask.rows == src.cols)) return 1;\r
+ if (countNonZero(mask) < mask.rows) return 2;\r
+ for (int i = 0; i < mask.rows; ++i) if (mask.at<uchar>(i, 0) > 1) return 3;\r
+ return 0;\r
+}\r
\r
- sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(3,1);\r
- types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC1;\r
- sizes[OUTPUT][1] = sizes[REF_OUTPUT][1] = cvSize(pt_count,1);\r
- types[OUTPUT][1] = types[REF_OUTPUT][1] = CV_8UC1;\r
- \r
- test_cpp = (cvtest::randInt(rng) & 256) == 0;\r
- */\r
+int CV_HomographyTest::check_ransac_mask_2(const Mat& original_mask, const Mat& found_mask)\r
+{\r
+ if (!(found_mask.cols == 1) && (found_mask.rows == original_mask.rows)) return 1;\r
+ for (int i = 0; i < found_mask.rows; ++i) if (found_mask.at<uchar>(i, 0) > 1) return 2;\r
+ return 0;\r
}\r
\r
-int CV_HomographyTest::read_params(CvFileStorage *fs)\r
+void CV_HomographyTest::print_information_1(int j, int N, int method, const Mat& H)\r
{\r
- int code = cvtest::ArrayTest::read_params(fs);\r
- return code;\r
+ cout << endl; cout << "Checking for homography matrix sizes..." << endl; cout << endl;\r
+ cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";\r
+ cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
+ cout << "Count of points: " << N << endl; cout << endl;\r
+ cout << "Method: "; if (method == 0) cout << 0; else if (method == 8) cout << "RANSAC"; else cout << "LMEDS"; cout << endl;\r
+ cout << "Homography matrix:" << endl; cout << endl;\r
+ cout << H << endl; cout << endl;\r
+ cout << "Number of rows: " << H.rows << " Number of cols: " << H.cols << endl; cout << endl;\r
}\r
\r
-double CV_HomographyTest::get_success_error_level(int test_case_idx, int i, int j) \r
+void CV_HomographyTest::print_information_2(int j, int N, int method, const Mat& H, const Mat& H_res, int k, double diff)\r
{\r
- return max_diff;\r
+ cout << endl; cout << "Checking for accuracy of homography matrix computing..." << endl; cout << endl;\r
+ cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";\r
+ cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
+ cout << "Count of points: " << N << endl; cout << endl;\r
+ cout << "Method: "; if (method == 0) cout << 0; else if (method == 8) cout << "RANSAC"; else cout << "LMEDS"; cout << endl;\r
+ cout << "Original matrix:" << endl; cout << endl;\r
+ cout << H << endl; cout << endl;\r
+ cout << "Found matrix:" << endl; cout << endl;\r
+ cout << H_res << endl; cout << endl;\r
+ cout << "Norm type using in criteria: "; if (NORM_TYPE[k] == 1) cout << "INF"; else if (NORM_TYPE[k] == 2) cout << "L1"; else cout << "L2"; cout << endl;\r
+ cout << "Difference between matrices: " << diff << endl;\r
+ cout << "Maximum allowed difference: " << max_diff << endl; cout << endl;\r
}\r
\r
-void CV_HomographyTest::fill_array( int test_case_idx, int i, int j, Mat& arr )\r
+void CV_HomographyTest::print_information_3(int j, int N, const Mat& mask)\r
{\r
- double t[9]={0};\r
- RNG& rng = ts->get_rng();\r
+ cout << endl; cout << "Checking for inliers/outliers mask..." << endl; cout << endl;\r
+ cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";\r
+ cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
+ cout << "Count of points: " << N << endl; cout << endl;\r
+ cout << "Method: RANSAC" << endl;\r
+ cout << "Found mask:" << endl; cout << endl;\r
+ cout << mask << endl; cout << endl;\r
+ cout << "Number of rows: " << mask.rows << " Number of cols: " << mask.cols << endl; cout << endl;\r
+}\r
\r
- if ( i != INPUT )\r
- {\r
- cvtest::ArrayTest::fill_array( test_case_idx, i, j, arr );\r
- return;\r
- }\r
+void CV_HomographyTest::print_information_4(int method, int j, int N, int k, int l, double diff)\r
+{\r
+ cout << endl; cout << "Checking for accuracy of reprojection error computing..." << endl; cout << endl;\r
+ cout << "Method: "; if (method == 0) cout << 0 << endl; else cout << "CV_LMEDS" << endl;\r
+ cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";\r
+ cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
+ cout << "Sigma of normal noise: " << sigma << endl;\r
+ cout << "Count of points: " << N << endl;\r
+ cout << "Number of point: " << k << endl;\r
+ cout << "Norm type using in criteria: "; if (NORM_TYPE[l] == 1) cout << "INF"; else if (NORM_TYPE[l] == 2) cout << "L1"; else cout << "L2"; cout << endl;\r
+ cout << "Difference with noise of point: " << diff << endl;\r
+ cout << "Maxumum allowed difference: " << max_2diff << endl; cout << endl;\r
+}\r
\r
- switch( j )\r
- {\r
- case 0:\r
- case 1:\r
- return; // fill them later in prepare_test_case\r
- case 2:\r
- {\r
- double* p = arr.ptr<double>();\r
- for( i = 0; i < arr.cols*3; i += 3 )\r
- {\r
- /* p[i] = cvtest::randReal(rng)*square_size;\r
- p[i+1] = cvtest::randReal(rng)*square_size;\r
- p[i+2] = cvtest::randReal(rng)*square_size + square_size; */\r
- }\r
- }\r
- break;\r
- case 3:\r
- {\r
- double r[3];\r
- Mat rot_vec( 3, 1, CV_64F, r );\r
- Mat rot_mat( 3, 3, CV_64F, t, 4*sizeof(t[0]) );\r
- r[0] = cvtest::randReal(rng)*CV_PI*2;\r
- r[1] = cvtest::randReal(rng)*CV_PI*2;\r
- r[2] = cvtest::randReal(rng)*CV_PI*2;\r
-\r
- cvtest::Rodrigues( rot_vec, rot_mat );\r
- /* t[3] = cvtest::randReal(rng)*square_size;\r
- t[7] = cvtest::randReal(rng)*square_size;\r
- t[11] = cvtest::randReal(rng)*square_size; */\r
- Mat( 3, 4, CV_64F, t ).convertTo(arr, arr.type());\r
- }\r
- break;\r
- case 4:\r
- case 5:\r
- {\r
- /* t[0] = t[4] = cvtest::randReal(rng)*(max_f - min_f) + min_f;\r
- t[2] = (img_size*0.5 + cvtest::randReal(rng)*4. - 2.)*t[0];\r
- t[5] = (img_size*0.5 + cvtest::randReal(rng)*4. - 2.)*t[4];\r
- t[8] = 1.0f;\r
- Mat( 3, 3, CV_64F, t ).convertTo( arr, arr.type() ); */\r
- break;\r
- }\r
- }\r
+void CV_HomographyTest::print_information_5(int method, int j, int N, int l, double diff)\r
+{ \r
+ cout << endl; cout << "Checking for accuracy of reprojection error computing..." << endl; cout << endl;\r
+ cout << "Method: "; if (method == 0) cout << 0 << endl; else cout << "CV_LMEDS" << endl;\r
+ cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";\r
+ cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
+ cout << "Sigma of normal noise: " << sigma << endl;\r
+ cout << "Count of points: " << N << endl;\r
+ cout << "Norm type using in criteria: "; if (NORM_TYPE[l] == 1) cout << "INF"; else if (NORM_TYPE[l] == 2) cout << "L1"; else cout << "L2"; cout << endl;\r
+ cout << "Difference with noise of points: " << diff << endl;\r
+ cout << "Maxumum allowed difference: " << max_diff << endl; cout << endl;\r
}\r
\r
-int CV_HomographyTest::prepare_test_case(int test_case_idx)\r
+void CV_HomographyTest::print_information_6(int j, int N, int k, double diff, bool value)\r
{\r
- int code = cvtest::ArrayTest::prepare_test_case(test_case_idx);\r
-\r
- if (code > 0) \r
- {\r
- Mat& src = test_mat[INPUT][0];\r
- RNG& rng = ts->get_rng();\r
-\r
- float Hdata[] = { sqrt(2.0f)/2, -sqrt(2.0f)/2, 0.0f, \r
- sqrt(2.0f)/2, sqrt(2.0f)/2, 0.0f, \r
- 0.0f, 0.0f, 1.0f };\r
- \r
- Mat H( 3, 3, CV_32F, Hdata );\r
-\r
- cv::Mat dst(1, src.cols, CV_32FC2);\r
- \r
- int k;\r
-\r
- for( k = 0; k < 2; k++ )\r
- {\r
- const Mat& H = test_mat[OUTPUT][0];\r
- Mat& dst = test_mat[INPUT][k == 0 ? 1 : 2];\r
-\r
- for (int i = 0; i < src.cols; ++i)\r
- {\r
- float *s = src.ptr<float>()+2*i;\r
- float *d = dst.ptr<float>()+2*i;\r
-\r
- d[0] = Hdata[0]*s[0] + Hdata[1]*s[1] + Hdata[2];\r
- d[1] = Hdata[3]*s[0] + Hdata[4]*s[1] + Hdata[5];\r
- }\r
-\r
- test_projectPoints( src, dst, H, &rng, sigma );\r
- }\r
- }\r
-\r
- return code;\r
+ cout << endl; cout << "Checking for inliers/outliers mask..." << endl; cout << endl;\r
+ cout << "Method: RANSAC" << endl;\r
+ cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";\r
+ cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
+ cout << "Count of points: " << N << " " << endl;\r
+ cout << "Number of point: " << k << " " << endl;\r
+ cout << "Reprojection error for this point: " << diff << " " << endl;\r
+ cout << "Reprojection error threshold: " << reproj_threshold << " " << endl;\r
+ cout << "Value of found mask: "<< value << endl; cout << endl;\r
}\r
\r
-static void test_convertHomogeneous( const Mat& _src, Mat& _dst )\r
+void CV_HomographyTest::print_information_7(int j, int N, int k, double diff, bool original_value, bool found_value)\r
{\r
- Mat src = _src, dst = _dst;\r
- \r
- int i, count, sdims, ddims;\r
- int sstep1, sstep2, dstep1, dstep2;\r
-\r
- if( src.depth() != CV_64F ) _src.convertTo(src, CV_64F);\r
- \r
- if( dst.depth() != CV_64F ) dst.create(dst.size(), CV_MAKETYPE(CV_64F, _dst.channels()));\r
-\r
- if( src.rows > src.cols )\r
- {\r
- count = src.rows;\r
- sdims = src.channels()*src.cols;\r
- sstep1 = (int)(src.step/sizeof(double));\r
- sstep2 = 1;\r
- }\r
- \r
- else\r
- {\r
- count = src.cols;\r
- sdims = src.channels()*src.rows;\r
- if( src.rows == 1 )\r
- {\r
- sstep1 = sdims;\r
- sstep2 = 1;\r
- }\r
- \r
- else\r
- {\r
- sstep1 = 1;\r
- sstep2 = (int)(src.step/sizeof(double));\r
- }\r
- }\r
-\r
- if( dst.rows > dst.cols )\r
- {\r
- if (count != dst.rows) ; // CV_Error should be here\r
- CV_Assert( count == dst.rows );\r
- ddims = dst.channels()*dst.cols;\r
- dstep1 = (int)(dst.step/sizeof(double));\r
- dstep2 = 1;\r
- }\r
- else\r
- {\r
- assert( count == dst.cols );\r
- ddims = dst.channels()*dst.rows;\r
- if( dst.rows == 1 )\r
- {\r
- dstep1 = ddims;\r
- dstep2 = 1;\r
- }\r
- else\r
- {\r
- dstep1 = 1;\r
- dstep2 = (int)(dst.step/sizeof(double));\r
- }\r
- }\r
+ cout << endl; cout << "Checking for inliers/outliers mask..." << endl; cout << endl;\r
+ cout << "Method: RANSAC" << endl;\r
+ cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";\r
+ cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
+ cout << "Count of points: " << N << " " << endl;\r
+ cout << "Number of point: " << k << " " << endl;\r
+ cout << "Reprojection error for this point: " << diff << " " << endl;\r
+ cout << "Reprojection error threshold: " << reproj_threshold << " " << endl;\r
+ cout << "Value of original mask: "<< original_value << " Value of found mask: " << found_value << endl; cout << endl;\r
+}\r
\r
- double* s = src.ptr<double>();\r
- double* d = dst.ptr<double>();\r
+void CV_HomographyTest::print_information_8(int j, int N, int k, int l, double diff)\r
+{\r
+ cout << endl; cout << "Checking for reprojection error of inlier..." << endl; cout << endl;\r
+ cout << "Method: RANSAC" << endl;\r
+ cout << "Sigma of normal noise: " << sigma << endl;\r
+ cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";\r
+ cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
+ cout << "Count of points: " << N << " " << endl;\r
+ cout << "Number of point: " << k << " " << endl;\r
+ cout << "Norm type using in criteria: "; if (NORM_TYPE[l] == 1) cout << "INF"; else if (NORM_TYPE[l] == 2) cout << "L1"; else cout << "L2"; cout << endl;\r
+ cout << "Difference with noise of point: " << diff << endl;\r
+ cout << "Maxumum allowed difference: " << max_2diff << endl; cout << endl;\r
+}\r
\r
- if( sdims <= ddims )\r
+void CV_HomographyTest::run(int)\r
+{\r
+ for (size_t N = 4; N <= MAX_COUNT_OF_POINTS; ++N)\r
{\r
- int wstep = dstep2*(ddims - 1);\r
+ RNG& rng = ts->get_rng();\r
\r
- for( i = 0; i < count; i++, s += sstep1, d += dstep1 )\r
- {\r
- double x = s[0];\r
- double y = s[sstep2];\r
-\r
- d[wstep] = 1;\r
- d[0] = x;\r
- d[dstep2] = y;\r
+ float *src_data = new float [2*N];\r
\r
- if( sdims >= 3 )\r
- {\r
- d[dstep2*2] = s[sstep2*2];\r
- if( sdims == 4 )\r
- d[dstep2*3] = s[sstep2*3];\r
- }\r
+ for (size_t i = 0; i < N; ++i)\r
+ {\r
+ src_data[2*i] = (float)cvtest::randReal(rng)*image_size;\r
+ src_data[2*i+1] = (float)cvtest::randReal(rng)*image_size;\r
}\r
- }\r
- else\r
- {\r
- int wstep = sstep2*(sdims - 1);\r
\r
- for( i = 0; i < count; i++, s += sstep1, d += dstep1 )\r
- {\r
- double w = s[wstep];\r
- double x = s[0];\r
- double y = s[sstep2];\r
+ cv::Mat src_mat_2f(1, N, CV_32FC2, src_data),\r
+ src_mat_2d(2, N, CV_32F, src_data),\r
+ src_mat_3d(3, N, CV_32F);\r
+ cv::Mat dst_mat_2f, dst_mat_2d, dst_mat_3d;\r
\r
- w = w ? 1./w : 1;\r
+ vector <Point2f> src_vec, dst_vec;\r
\r
- d[0] = x*w;\r
- d[dstep2] = y*w;\r
+ for (size_t i = 0; i < N; ++i)\r
+ {\r
+ float *tmp = src_mat_2d.ptr<float>()+2*i;\r
+ src_mat_3d.at<float>(0, i) = tmp[0];\r
+ src_mat_3d.at<float>(1, i) = tmp[1];\r
+ src_mat_3d.at<float>(2, i) = 1.0f;\r
\r
- if( ddims == 3 )\r
- d[dstep2*2] = s[sstep2*2]*w;\r
+ src_vec.push_back(Point2f(tmp[0], tmp[1]));\r
}\r
- }\r
\r
- if( dst.data != _dst.data )\r
- dst.convertTo(_dst, _dst.depth());\r
-}\r
+ double fi = cvtest::randReal(rng)*2*CV_PI;\r
\r
-void CV_HomographyTest::test_projectPoints( Mat& src_2d, Mat& dst, const Mat& H, RNG* rng, double sigma )\r
-{\r
- if (!src_2d.isContinuous()) \r
- {\r
- CV_Error(-1, "");\r
- return;\r
- }\r
-\r
- cv::Mat src_3d(1, src_2d.cols, CV_32FC3);\r
- \r
- for (int i = 0; i < src_2d.cols; ++i)\r
- { \r
- float *c_3d = src_3d.ptr<float>()+3*i;\r
- float *c_2d = src_2d.ptr<float>()+2*i;\r
-\r
- c_3d[0] = c_2d[0]; c_3d[1] = c_2d[1]; c_3d[2] = 1.0f;\r
- }\r
-\r
- cv::Mat dst_3d; gemm(H, src_3d, 1, Mat(), 0, dst_3d);\r
- \r
- int i, count = src_2d.cols;\r
-\r
- Mat noise;\r
-\r
- if ( rng )\r
- {\r
- if( sigma == 0 ) rng = 0;\r
- else\r
- {\r
- noise.create( 1, count, CV_32FC2 );\r
- rng->fill(noise, RNG::NORMAL, Scalar::all(0), Scalar::all(sigma) );\r
- }\r
- }\r
-\r
- cv::Mat dst_2d(1, count, CV_32FC2); \r
- \r
- for (size_t i = 0; i < count; ++i)\r
- {\r
- float *c_3d = dst_3d.ptr<float>()+3*i;\r
- float *c_2d = dst_2d.ptr<float>()+2*i;\r
-\r
- c_2d[0] = c_3d[0]/c_3d[2];\r
- c_2d[1] = c_3d[1]/c_3d[2];\r
- }\r
-\r
- Mat temp( 1, count, CV_32FC2 );\r
-\r
- for( i = 0; i < count; i++ )\r
- {\r
- const double* M = src_2d.ptr<double>() + 2*i;\r
- double* m = temp.ptr<double>() + 2*i;\r
- double X = M[0], Y = M[1], Z = M[2];\r
- double u = H.at<float>(0, 0)*X + H.at<float>(0, 1)*Y + H.at<float>(0, 2);\r
- double v = H.at<float>(1, 0)*X + H.at<float>(1, 1)*Y + H.at<float>(1, 2);\r
- double s = H.at<float>(2, 0)*X + H.at<float>(2, 1)*Y + H.at<float>(2, 2);\r
-\r
- if( !noise.empty() )\r
- {\r
- u += noise.at<Point2f>(i).x*s;\r
- v += noise.at<Point2f>(i).y*s;\r
- }\r
-\r
- m[0] = u;\r
- m[1] = v;\r
- m[2] = s;\r
- }\r
-\r
- test_convertHomogeneous( dst_2d, dst );\r
-}\r
+ double t_x = cvtest::randReal(rng)*sqrt(image_size*1.0),\r
+ t_y = cvtest::randReal(rng)*sqrt(image_size*1.0);\r
\r
-void CV_HomographyTest::prepare_to_validation(int test_case_idx)\r
-{\r
- const Mat& H = test_mat[INPUT][3];\r
- \r
- const Mat& A1 = test_mat[INPUT][4];\r
- const Mat& A2 = test_mat[INPUT][5];\r
- \r
- double h0[9], h[9];\r
- Mat H0(3, 3, CV_32FC1, h0);\r
+ double Hdata[9] = { cos(fi), -sin(fi), t_x,\r
+ sin(fi), cos(fi), t_y,\r
+ 0.0f, 0.0f, 1.0f };\r
\r
- Mat invA1, invA2, T;\r
+ cv::Mat H_64(3, 3, CV_64F, Hdata), H_32;\r
\r
- cv::invert(A1, invA1, CV_SVD);\r
- cv::invert(A2, invA2, CV_SVD);\r
+ H_64.convertTo(H_32, CV_32F);\r
\r
- double tx = H.at<double>(0, 2);\r
- double ty = H.at<double>(1, 2);\r
- double tz = H.at<double>(2, 2);\r
+ dst_mat_3d = H_32*src_mat_3d;\r
\r
- // double _t_x[] = { 0, -tz, ty, tz, 0, -tx, -ty, tx, 0 };\r
+ dst_mat_2d.create(2, N, CV_32F); dst_mat_2f.create(1, N, CV_32FC2);\r
\r
- // F = (A2^-T)*[t]_x*R*(A1^-1)\r
- /* cv::gemm( invA2, Mat( 3, 3, CV_64F, _t_x ), 1, Mat(), 0, T, CV_GEMM_A_T );\r
- cv::gemm( R, invA1, 1, Mat(), 0, invA2 );\r
- cv::gemm( T, invA2, 1, Mat(), 0, F0 ); */\r
- H0 *= 1./h0[8];\r
+ for (size_t i = 0; i < N; ++i)\r
+ {\r
+ float *tmp_2f = dst_mat_2f.ptr<float>()+2*i;\r
+ tmp_2f[0] = dst_mat_2d.at<float>(0, i) = dst_mat_3d.at<float>(0, i) /= dst_mat_3d.at<float>(2, i);\r
+ tmp_2f[1] = dst_mat_2d.at<float>(1, i) = dst_mat_3d.at<float>(1, i) /= dst_mat_3d.at<float>(2, i);\r
+ dst_mat_3d.at<float>(2, i) = 1.0f;\r
\r
- uchar* status = test_mat[TEMP][1].data;\r
- double err_level = get_success_error_level( test_case_idx, OUTPUT, 1 );\r
- uchar* mtfm1 = test_mat[REF_OUTPUT][1].data;\r
- uchar* mtfm2 = test_mat[OUTPUT][1].data;\r
- double* f_prop1 = (double*)test_mat[REF_OUTPUT][0].data;\r
- double* f_prop2 = (double*)test_mat[OUTPUT][0].data;\r
+ dst_vec.push_back(Point2f(tmp_2f[0], tmp_2f[1]));\r
+ }\r
\r
- int i, pt_count = test_mat[INPUT][2].cols;\r
- Mat p1( 1, pt_count, CV_64FC2 );\r
- Mat p2( 1, pt_count, CV_64FC2 );\r
+ for (size_t i = 0; i < METHODS_COUNT; ++i)\r
+ {\r
+ method = METHOD[i];\r
+ switch (method)\r
+ {\r
+ case 0:\r
+ case CV_LMEDS:\r
+ {\r
+ Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, method),\r
+ cv::findHomography(src_mat_2f, dst_vec, method),\r
+ cv::findHomography(src_vec, dst_mat_2f, method),\r
+ cv::findHomography(src_vec, dst_vec, method) };\r
+\r
+ for (size_t j = 0; j < 4; ++j)\r
+ {\r
+\r
+ if (!check_matrix_size(H_res_64[j]))\r
+ {\r
+ print_information_1(j, N, method, H_res_64[j]);\r
+ CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE, MESSAGE_MATRIX_SIZE);\r
+ return;\r
+ }\r
+\r
+ double diff;\r
+\r
+ for (size_t k = 0; k < COUNT_NORM_TYPES; ++k)\r
+ if (!check_matrix_diff(H_64, H_res_64[j], NORM_TYPE[k], diff))\r
+ {\r
+ print_information_2(j, N, method, H_64, H_res_64[j], k, diff);\r
+ CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_DIFF, MESSAGE_MATRIX_DIFF);\r
+ return;\r
+ }\r
+ }\r
+\r
+ continue;\r
+ }\r
+ case CV_RANSAC:\r
+ {\r
+ cv::Mat mask [4]; double diff;\r
+\r
+ Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, CV_RANSAC, reproj_threshold, mask[0]),\r
+ cv::findHomography(src_mat_2f, dst_vec, CV_RANSAC, reproj_threshold, mask[1]),\r
+ cv::findHomography(src_vec, dst_mat_2f, CV_RANSAC, reproj_threshold, mask[2]),\r
+ cv::findHomography(src_vec, dst_vec, CV_RANSAC, reproj_threshold, mask[3]) };\r
+\r
+ for (size_t j = 0; j < 4; ++j)\r
+ {\r
+\r
+ if (!check_matrix_size(H_res_64[j]))\r
+ {\r
+ print_information_1(j, N, method, H_res_64[j]);\r
+ CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE, MESSAGE_MATRIX_SIZE);\r
+ return;\r
+ }\r
+\r
+ for (size_t k = 0; k < COUNT_NORM_TYPES; ++k)\r
+ if (!check_matrix_diff(H_64, H_res_64[j], NORM_TYPE[k], diff))\r
+ {\r
+ print_information_2(j, N, method, H_64, H_res_64[j], k, diff);\r
+ CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_DIFF, MESSAGE_MATRIX_DIFF);\r
+ return;\r
+ }\r
+\r
+ int code = check_ransac_mask_1(src_mat_2f, mask[j]);\r
+\r
+ if (code)\r
+ {\r
+ print_information_3(j, N, mask[j]);\r
+ \r
+ switch (code)\r
+ {\r
+ case 1: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_1); break; }\r
+ case 2: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_2); break; }\r
+ case 3: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_3); break; }\r
+\r
+ default: break;\r
+ }\r
+ \r
+ return;\r
+ }\r
\r
- test_convertHomogeneous( test_mat[INPUT][0], p1 );\r
- test_convertHomogeneous( test_mat[INPUT][1], p2 );\r
+ }\r
\r
- cvtest::convert(test_mat[TEMP][0], H0, H.type());\r
+ continue;\r
+ }\r
\r
- if( method <= CV_FM_8POINT )\r
- memset( status, 1, pt_count );\r
+ default: continue;\r
+ }\r
+ }\r
\r
- for( i = 0; i < pt_count; i++ )\r
- {\r
- double x1 = p1.at<Point2f>(i).x;\r
- double y1 = p1.at<Point2f>(i).y;\r
- double x2 = p2.at<Point2f>(i).x;\r
- double y2 = p2.at<Point2f>(i).y;\r
- double n1 = 1./sqrt(x1*x1 + y1*y1 + 1);\r
- double n2 = 1./sqrt(x2*x2 + y2*y2 + 1);\r
- double t0 = fabs(h0[0]*x2*x1 + h0[1]*x2*y1 + h0[2]*x2 +\r
- h0[3]*y2*x1 + h0[4]*y2*y1 + h0[5]*y2 +\r
- h0[6]*x1 + h0[7]*y1 + h0[8])*n1*n2;\r
- double t = fabs(h[0]*x2*x1 + h[1]*x2*y1 + h[2]*x2 +\r
- h[3]*y2*x1 + h[4]*y2*y1 + h[5]*y2 +\r
- h[6]*x1 + h[7]*y1 + h[8])*n1*n2;\r
- mtfm1[i] = 1;\r
- mtfm2[i] = !status[i] || t0 > err_level || t < err_level;\r
- }\r
+ Mat noise_2f(1, N, CV_32FC2);\r
+ rng.fill(noise_2f, RNG::NORMAL, Scalar::all(0), Scalar::all(sigma));\r
\r
- f_prop1[0] = 1;\r
- f_prop1[1] = 1;\r
- f_prop1[2] = 0;\r
+ cv::Mat mask(N, 1, CV_8UC1);\r
\r
- // f_prop2[0] = f_result != 0;\r
- f_prop2[1] = h[8];\r
- f_prop2[2] = cv::determinant( H );\r
-}\r
+ for (size_t i = 0; i < N; ++i)\r
+ {\r
+ float *a = noise_2f.ptr<float>()+2*i, *_2f = dst_mat_2f.ptr<float>()+2*i;\r
+ _2f[0] += a[0]; _2f[1] += a[1];\r
+ mask.at<bool>(i, 0) = !(sqrt(a[0]*a[0]+a[1]*a[1]) > reproj_threshold);\r
+ }\r
\r
-bool CV_HomographyTest::check_matrix_size(const cv::Mat& H) \r
-{\r
- return (H.rows == 3) && (H.cols == 3);\r
-}\r
+ for (size_t i = 0; i < METHODS_COUNT; ++i)\r
+ {\r
+ method = METHOD[i];\r
+ switch (method)\r
+ {\r
+ case 0:\r
+ case CV_LMEDS:\r
+ {\r
+ Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f),\r
+ cv::findHomography(src_mat_2f, dst_vec),\r
+ cv::findHomography(src_vec, dst_mat_2f),\r
+ cv::findHomography(src_vec, dst_vec) };\r
\r
-bool CV_HomographyTest::check_matrix_diff(const cv::Mat& original, const cv::Mat& found, const int norm_type, double &diff)\r
-{\r
- diff = cv::norm(original, found, norm_type);\r
- return diff <= max_diff;\r
-}\r
+ for (size_t j = 0; j < 4; ++j)\r
+ {\r
\r
-int CV_HomographyTest::check_ransac_mask_1(const Mat& src, const Mat& mask)\r
-{\r
- if (!(mask.cols == 1) && (mask.rows == src.cols)) return 1;\r
- if (countNonZero(mask) < mask.rows) return 2;\r
- for (size_t i = 0; i < mask.rows; ++i) if (mask.at<uchar>(i, 0) > 1) return 3;\r
- return 0;\r
-}\r
+ if (!check_matrix_size(H_res_64[j]))\r
+ {\r
+ print_information_1(j, N, method, H_res_64[j]);\r
+ CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE, MESSAGE_MATRIX_SIZE);\r
+ return;\r
+ }\r
\r
-int CV_HomographyTest::check_ransac_mask_2(const Mat& original_mask, const Mat& found_mask)\r
-{\r
- if (!(found_mask.cols == 1) && (found_mask.rows == original_mask.rows)) return 1;\r
- for (size_t i = 0; i < found_mask.rows; ++i) if (found_mask.at<uchar>(i, 0) > 1) return 2;\r
- return 0;\r
-}\r
+ Mat H_res_32; H_res_64[j].convertTo(H_res_32, CV_32F);\r
\r
-void CV_HomographyTest::print_information_1(int j, int N, int method, const Mat& H)\r
-{\r
- cout << endl; cout << "Checking for homography matrix sizes..." << endl; cout << endl;\r
- cout << "Type of srcPoints: "; if (0 <= j < 2) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; \r
- cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
- cout << "Count of points: " << N << endl; cout << endl;\r
- cout << "Method: "; if (method == 0) cout << 0; else if (method == 8) cout << "RANSAC"; else cout << "LMEDS"; cout << endl;\r
- cout << "Homography matrix:" << endl; cout << endl;\r
- cout << H << endl; cout << endl;\r
- cout << "Number of rows: " << H.rows << " Number of cols: " << H.cols << endl; cout << endl;\r
-}\r
+ cv::Mat dst_res_3d(3, N, CV_32F), noise_2d(2, N, CV_32F);\r
\r
-void CV_HomographyTest::print_information_2(int j, int N, int method, const Mat& H, const Mat& H_res, int k, double diff)\r
-{\r
- cout << endl; cout << "Checking for accuracy of homography matrix computing..." << endl; cout << endl;\r
- cout << "Type of srcPoints: "; if (0 <= j < 2) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; \r
- cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
- cout << "Count of points: " << N << endl; cout << endl;\r
- cout << "Method: "; if (method == 0) cout << 0; else if (method == 8) cout << "RANSAC"; else cout << "LMEDS"; cout << endl;\r
- cout << "Original matrix:" << endl; cout << endl;\r
- cout << H << endl; cout << endl;\r
- cout << "Found matrix:" << endl; cout << endl;\r
- cout << H_res << endl; cout << endl;\r
- cout << "Norm type using in criteria: "; if (NORM_TYPE[k] == 1) cout << "INF"; else if (NORM_TYPE[k] == 2) cout << "L1"; else cout << "L2"; cout << endl;\r
- cout << "Difference between matrix: " << diff << endl;\r
- cout << "Maximum allowed difference: " << max_diff << endl; cout << endl;\r
-}\r
+ for (size_t k = 0; k < N; ++k)\r
+ {\r
\r
-void CV_HomographyTest::print_information_3(int j, int N, const Mat& mask)\r
-{\r
- cout << endl; cout << "Checking for inliers/outliers mask..." << endl; cout << endl;\r
- cout << "Type of srcPoints: "; if (0 <= j < 2) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; \r
- cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
- cout << "Count of points: " << N << endl; cout << endl;\r
- cout << "Method: RANSAC" << endl;\r
- cout << "Found mask:" << endl; cout << endl;\r
- cout << mask << endl; cout << endl;\r
- cout << "Number of rows: " << mask.rows << " Number of cols: " << mask.cols << endl; cout << endl;\r
-}\r
+ Mat tmp_mat_3d = H_res_32*src_mat_3d.col(k);\r
\r
-void CV_HomographyTest::print_information_4(int method, int j, int N, int k, int l, double diff)\r
-{\r
- cout << endl; cout << "Checking for accuracy of reprojection error computing..." << endl; cout << endl;\r
- cout << "Method: "; if (method == 0) cout << 0 << endl; else cout << "CV_LMEDS" << endl;\r
- cout << "Type of srcPoints: "; if (0 <= j < 2) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; \r
- cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
- cout << "Sigma of normal noise: " << sigma << endl;\r
- cout << "Count of points: " << N << endl;\r
- cout << "Number of point: " << k << endl;\r
- cout << "Norm type using in criteria: "; if (NORM_TYPE[l] == 1) cout << "INF"; else if (NORM_TYPE[l] == 2) cout << "L1"; else cout << "L2"; cout << endl;\r
- cout << "Difference with noise of point: " << diff << endl; \r
- cout << "Maxumum allowed difference: " << max_2diff << endl; cout << endl;\r
-}\r
+ dst_res_3d.at<float>(0, k) = tmp_mat_3d.at<float>(0, 0) /= tmp_mat_3d.at<float>(2, 0);\r
+ dst_res_3d.at<float>(1, k) = tmp_mat_3d.at<float>(1, 0) /= tmp_mat_3d.at<float>(2, 0);\r
+ dst_res_3d.at<float>(2, k) = tmp_mat_3d.at<float>(2, 0) = 1.0f;\r
\r
-void CV_HomographyTest::print_information_5(int method, int j, int N, int l, double diff)\r
-{ \r
- cout << endl; cout << "Checking for accuracy of reprojection error computing..." << endl; cout << endl;\r
- cout << "Method: "; if (method == 0) cout << 0 << endl; else cout << "CV_LMEDS" << endl;\r
- cout << "Type of srcPoints: "; if (0 <= j < 2) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; \r
- cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
- cout << "Sigma of normal noise: " << sigma << endl;\r
- cout << "Count of points: " << N << endl;\r
- cout << "Norm type using in criteria: "; if (NORM_TYPE[l] == 1) cout << "INF"; else if (NORM_TYPE[l] == 2) cout << "L1"; else cout << "L2"; cout << endl; \r
- cout << "Difference with noise of points: " << diff << endl; \r
- cout << "Maxumum allowed difference: " << max_diff << endl; cout << endl; \r
-}\r
+ float *a = noise_2f.ptr<float>()+2*k;\r
+ noise_2d.at<float>(0, k) = a[0]; noise_2d.at<float>(1, k) = a[1];\r
\r
-void CV_HomographyTest::print_information_6(int j, int N, int k, double diff, bool value)\r
-{\r
- cout << endl; cout << "Checking for inliers/outliers mask..." << endl; cout << endl;\r
- cout << "Method: RANSAC" << endl;\r
- cout << "Type of srcPoints: "; if (0 <= j < 2) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; \r
- cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
- cout << "Count of points: " << N << " " << endl; \r
- cout << "Number of point: " << k << " " << endl;\r
- cout << "Reprojection error for this point: " << diff << " " << endl;\r
- cout << "Reprojection error threshold: " << reproj_threshold << " " << endl;\r
- cout << "Value of found mask: "<< value << endl; cout << endl;\r
-}\r
+ for (size_t l = 0; l < COUNT_NORM_TYPES; ++l)\r
+ if (cv::norm(tmp_mat_3d, dst_mat_3d.col(k), NORM_TYPE[l]) - cv::norm(noise_2d.col(k), NORM_TYPE[l]) > max_2diff)\r
+ {\r
+ print_information_4(method, j, N, k, l, cv::norm(tmp_mat_3d, dst_mat_3d.col(k), NORM_TYPE[l]) - cv::norm(noise_2d.col(k), NORM_TYPE[l]));\r
+ CV_Error(CALIB3D_HOMOGRAPHY_ERROR_REPROJ_DIFF, MESSAGE_REPROJ_DIFF_1);\r
+ return;\r
+ }\r
\r
-void CV_HomographyTest::print_information_7(int j, int N, int k, double diff, bool original_value, bool found_value)\r
-{\r
- cout << endl; cout << "Checking for inliers/outliers mask..." << endl; cout << endl;\r
- cout << "Method: RANSAC" << endl;\r
- cout << "Type of srcPoints: "; if (0 <= j < 2) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; \r
- cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
- cout << "Count of points: " << N << " " << endl; \r
- cout << "Number of point: " << k << " " << endl;\r
- cout << "Reprojection error for this point: " << diff << " " << endl;\r
- cout << "Reprojection error threshold: " << reproj_threshold << " " << endl;\r
- cout << "Value of original mask: "<< original_value << " Value of found mask: " << found_value << endl; cout << endl;\r
-}\r
+ }\r
\r
-void CV_HomographyTest::print_information_8(int j, int N, int k, int l, double diff)\r
-{\r
- cout << endl; cout << "Checking for reprojection error of inlier..." << endl; cout << endl;\r
- cout << "Method: RANSAC" << endl;\r
- cout << "Sigma of normal noise: " << sigma << endl;\r
- cout << "Type of srcPoints: "; if (0 <= j < 2) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; \r
- cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;\r
- cout << "Count of points: " << N << " " << endl; \r
- cout << "Number of point: " << k << " " << endl;\r
- cout << "Norm type using in criteria: "; if (NORM_TYPE[l] == 1) cout << "INF"; else if (NORM_TYPE[l] == 2) cout << "L1"; else cout << "L2"; cout << endl; \r
- cout << "Difference with noise of point: " << diff << endl;\r
- cout << "Maxumum allowed difference: " << max_2diff << endl; cout << endl;\r
-}\r
+ Mat tmp_mat_3d = H_res_32*src_mat_3d;\r
\r
-void CV_HomographyTest::check_transform_quality(cv::InputArray src_points, cv::InputArray dst_points, const cv::Mat& H, const int norm_type)\r
-{ \r
- Mat src, dst_original; \r
- cv::transpose(src_points.getMat(), src); cv::transpose(dst_points.getMat(), dst_original);\r
- cv::Mat src_3d(src.rows+1, src.cols, CV_32FC1);\r
- src_3d(Rect(0, 0, src.rows, src.cols)) = src;\r
- src_3d(Rect(src.rows, 0, 1, src.cols)) = Mat(1, src.cols, CV_32FC1, Scalar(1.0f));\r
- \r
- cv::Mat dst_found, dst_found_3d;\r
- cv::multiply(H, src_3d, dst_found_3d); \r
- dst_found = dst_found_3d/dst_found_3d.row(dst_found_3d.rows-1);\r
- double reprojection_error = cv::norm(dst_original, dst_found, norm_type);\r
- CV_Assert ( reprojection_error > max_diff );\r
-}\r
+ for (size_t l = 0; l < COUNT_NORM_TYPES; ++l)\r
+ if (cv::norm(dst_res_3d, dst_mat_3d, NORM_TYPE[l]) - cv::norm(noise_2d, NORM_TYPE[l]) > max_diff)\r
+ {\r
+ print_information_5(method, j, N, l, cv::norm(dst_res_3d, dst_mat_3d, NORM_TYPE[l]) - cv::norm(noise_2d, NORM_TYPE[l]));\r
+ CV_Error(CALIB3D_HOMOGRAPHY_ERROR_REPROJ_DIFF, MESSAGE_REPROJ_DIFF_2);\r
+ return;\r
+ }\r
\r
-void CV_HomographyTest::run(int)\r
-{\r
- for (size_t N = 4; N <= MAX_COUNT_OF_POINTS; ++N)\r
- {\r
- RNG& rng = ts->get_rng();\r
-\r
- float *src_data = new float [2*N];\r
-\r
- for (int i = 0; i < N; ++i)\r
- {\r
- src_data[2*i] = (float)cvtest::randReal(rng)*image_size;\r
- src_data[2*i+1] = (float)cvtest::randReal(rng)*image_size;\r
- }\r
- \r
- cv::Mat src_mat_2f(1, N, CV_32FC2, src_data), \r
- src_mat_2d(2, N, CV_32F, src_data), \r
- src_mat_3d(3, N, CV_32F);\r
- cv::Mat dst_mat_2f, dst_mat_2d, dst_mat_3d;\r
-\r
- vector <Point2f> src_vec, dst_vec;\r
-\r
- for (size_t i = 0; i < N; ++i)\r
- {\r
- float *tmp = src_mat_2d.ptr<float>()+2*i;\r
- src_mat_3d.at<float>(0, i) = tmp[0];\r
- src_mat_3d.at<float>(1, i) = tmp[1];\r
- src_mat_3d.at<float>(2, i) = 1.0f;\r
-\r
- src_vec.push_back(Point2f(tmp[0], tmp[1]));\r
- }\r
-\r
- double fi = cvtest::randReal(rng)*2*CV_PI;\r
-\r
- double t_x = cvtest::randReal(rng)*sqrt(image_size*1.0), \r
- t_y = cvtest::randReal(rng)*sqrt(image_size*1.0);\r
-\r
- double Hdata[9] = { cos(fi), -sin(fi), t_x, \r
- sin(fi), cos(fi), t_y,\r
- 0.0f, 0.0f, 1.0f };\r
-\r
- cv::Mat H_64(3, 3, CV_64F, Hdata), H_32;\r
-\r
- H_64.convertTo(H_32, CV_32F);\r
-\r
- dst_mat_3d = H_32*src_mat_3d;\r
-\r
- dst_mat_2d.create(2, N, CV_32F); dst_mat_2f.create(1, N, CV_32FC2);\r
-\r
- for (size_t i = 0; i < N; ++i)\r
- {\r
- float *tmp_2f = dst_mat_2f.ptr<float>()+2*i;\r
- tmp_2f[0] = dst_mat_2d.at<float>(0, i) = dst_mat_3d.at<float>(0, i) /= dst_mat_3d.at<float>(2, i);\r
- tmp_2f[1] = dst_mat_2d.at<float>(1, i) = dst_mat_3d.at<float>(1, i) /= dst_mat_3d.at<float>(2, i);\r
- dst_mat_3d.at<float>(2, i) = 1.0f;\r
-\r
- dst_vec.push_back(Point2f(tmp_2f[0], tmp_2f[1]));\r
- }\r
-\r
- for (size_t i = 0; i < METHODS_COUNT; ++i)\r
- {\r
- method = METHOD[i];\r
- switch (method)\r
- {\r
- case 0:\r
- case CV_LMEDS:\r
- {\r
- Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, method),\r
- cv::findHomography(src_mat_2f, dst_vec, method), \r
- cv::findHomography(src_vec, dst_mat_2f, method),\r
- cv::findHomography(src_vec, dst_vec, method) };\r
- \r
- for (size_t j = 0; j < 4; ++j)\r
- {\r
- \r
- if (!check_matrix_size(H_res_64[j]))\r
- {\r
- print_information_1(j, N, method, H_res_64[j]);\r
- CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE, MESSAGE_MATRIX_SIZE);\r
- return;\r
- }\r
-\r
- double diff;\r
-\r
- for (size_t k = 0; k < COUNT_NORM_TYPES; ++k)\r
- if (!check_matrix_diff(H_64, H_res_64[j], NORM_TYPE[k], diff)) \r
- {\r
- print_information_2(j, N, method, H_64, H_res_64[j], k, diff);\r
- CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_DIFF, MESSAGE_MATRIX_DIFF);\r
- return;\r
- }\r
- }\r
-\r
- continue;\r
- }\r
- case CV_RANSAC:\r
- {\r
- cv::Mat mask [4]; double diff; \r
- \r
- Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, CV_RANSAC, reproj_threshold, mask[0]),\r
- cv::findHomography(src_mat_2f, dst_vec, CV_RANSAC, reproj_threshold, mask[1]),\r
- cv::findHomography(src_vec, dst_mat_2f, CV_RANSAC, reproj_threshold, mask[2]),\r
- cv::findHomography(src_vec, dst_vec, CV_RANSAC, reproj_threshold, mask[3]) };\r
-\r
- for (size_t j = 0; j < 4; ++j)\r
- {\r
-\r
- if (!check_matrix_size(H_res_64[j])) \r
- {\r
- print_information_1(j, N, method, H_res_64[j]);\r
- CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE, MESSAGE_MATRIX_SIZE);\r
- return;\r
- }\r
-\r
- for (size_t k = 0; k < COUNT_NORM_TYPES; ++k)\r
- if (!check_matrix_diff(H_64, H_res_64[j], NORM_TYPE[k], diff)) \r
- {\r
- print_information_2(j, N, method, H_64, H_res_64[j], k, diff);\r
- CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_DIFF, MESSAGE_MATRIX_DIFF);\r
- return;\r
- }\r
-\r
- int code = check_ransac_mask_1(src_mat_2f, mask[j]);\r
-\r
- if (code)\r
- {\r
- print_information_3(j, N, mask[j]);\r
- \r
- switch (code)\r
- {\r
- case 1: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_1); break; }\r
- case 2: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_2); break; }\r
- case 3: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_3); break; }\r
-\r
- default: break;\r
- }\r
- \r
- return;\r
- }\r
-\r
- }\r
-\r
- continue;\r
- }\r
- \r
- default: continue;\r
- } \r
- }\r
-\r
- Mat noise_2f(1, N, CV_32FC2);\r
- rng.fill(noise_2f, RNG::NORMAL, Scalar::all(0), Scalar::all(sigma));\r
-\r
- cv::Mat mask(N, 1, CV_8UC1);\r
-\r
- for (int i = 0; i < N; ++i)\r
- {\r
- float *a = noise_2f.ptr<float>()+2*i, *_2f = dst_mat_2f.ptr<float>()+2*i;\r
- _2f[0] /* = dst_mat_2d.at<float>(0, i) = dst_mat_3d.at<float>(0, i) */ += a[0];\r
- _2f[1] /* = dst_mat_2d.at<float>(1, i) = dst_mat_3d.at<float>(1, i) */ += a[1];\r
- mask.at<bool>(i, 0) = !(sqrt(a[0]*a[0]+a[1]*a[1]) > reproj_threshold);\r
- }\r
-\r
- for (size_t i = 0; i < METHODS_COUNT; ++i)\r
- {\r
- method = METHOD[i];\r
- switch (method)\r
- {\r
- case 0:\r
- case CV_LMEDS:\r
- {\r
- Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f),\r
- cv::findHomography(src_mat_2f, dst_vec),\r
- cv::findHomography(src_vec, dst_mat_2f),\r
- cv::findHomography(src_vec, dst_vec) };\r
-\r
- for (size_t j = 0; j < 4; ++j)\r
- {\r
- \r
- if (!check_matrix_size(H_res_64[j]))\r
- {\r
- print_information_1(j, N, method, H_res_64[j]);\r
- CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE, MESSAGE_MATRIX_SIZE);\r
- return;\r
- }\r
-\r
- Mat H_res_32; H_res_64[j].convertTo(H_res_32, CV_32F);\r
-\r
- cv::Mat dst_res_3d(3, N, CV_32F), noise_2d(2, N, CV_32F);\r
-\r
- for (size_t k = 0; k < N; ++k)\r
- {\r
-\r
- Mat tmp_mat_3d = H_res_32*src_mat_3d.col(k);\r
-\r
- dst_res_3d.at<float>(0, k) = tmp_mat_3d.at<float>(0, 0) /= tmp_mat_3d.at<float>(2, 0);\r
- dst_res_3d.at<float>(1, k) = tmp_mat_3d.at<float>(1, 0) /= tmp_mat_3d.at<float>(2, 0);\r
- dst_res_3d.at<float>(2, k) = tmp_mat_3d.at<float>(2, 0) = 1.0f;\r
-\r
- float *a = noise_2f.ptr<float>()+2*k;\r
- noise_2d.at<float>(0, k) = a[0]; noise_2d.at<float>(1, k) = a[1];\r
- \r
- for (size_t l = 0; l < COUNT_NORM_TYPES; ++l) \r
- if (cv::norm(tmp_mat_3d, dst_mat_3d.col(k), NORM_TYPE[l]) - cv::norm(noise_2d.col(k), NORM_TYPE[l]) > max_2diff) \r
- {\r
- print_information_4(method, j, N, k, l, cv::norm(tmp_mat_3d, dst_mat_3d.col(k), NORM_TYPE[l]) - cv::norm(noise_2d.col(k), NORM_TYPE[l]));\r
- CV_Error(CALIB3D_HOMOGRAPHY_ERROR_REPROJ_DIFF, MESSAGE_REPROJ_DIFF_1);\r
- return;\r
- } \r
- \r
- }\r
- \r
- Mat tmp_mat_3d = H_res_32*src_mat_3d;\r
- \r
- for (size_t l = 0; l < COUNT_NORM_TYPES; ++l)\r
- if (cv::norm(dst_res_3d, dst_mat_3d, NORM_TYPE[l]) - cv::norm(noise_2d, NORM_TYPE[l]) > max_diff) \r
- {\r
- print_information_5(method, j, N, l, cv::norm(dst_res_3d, dst_mat_3d, NORM_TYPE[l]) - cv::norm(noise_2d, NORM_TYPE[l]));\r
- CV_Error(CALIB3D_HOMOGRAPHY_ERROR_REPROJ_DIFF, MESSAGE_REPROJ_DIFF_2);\r
- return;\r
- } \r
-\r
- }\r
- \r
- continue;\r
+ }\r
+\r
+ continue;\r
}\r
- case CV_RANSAC:\r
- {\r
- cv::Mat mask_res [4]; \r
-\r
- Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, CV_RANSAC, reproj_threshold, mask_res[0]),\r
- cv::findHomography(src_mat_2f, dst_vec, CV_RANSAC, reproj_threshold, mask_res[1]),\r
- cv::findHomography(src_vec, dst_mat_2f, CV_RANSAC, reproj_threshold, mask_res[2]),\r
- cv::findHomography(src_vec, dst_vec, CV_RANSAC, reproj_threshold, mask_res[3]) };\r
-\r
- for (size_t j = 0; j < 4; ++j)\r
- {\r
-\r
- if (!check_matrix_size(H_res_64[j])) \r
- {\r
- print_information_1(j, N, method, H_res_64[j]);\r
- CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE, MESSAGE_MATRIX_SIZE);\r
- return;\r
- }\r
- \r
- int code = check_ransac_mask_2(mask, mask_res[j]);\r
-\r
- if (code)\r
- {\r
- print_information_3(j, N, mask_res[j]);\r
- \r
- switch (code)\r
- {\r
- case 1: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_1); break; }\r
- case 2: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_3); break; }\r
- \r
- default: break;\r
- }\r
-\r
- return;\r
- }\r
-\r
- cv::Mat H_res_32; H_res_64[j].convertTo(H_res_32, CV_32F);\r
-\r
- cv::Mat dst_res_3d = H_res_32*src_mat_3d;\r
-\r
- for (size_t k = 0; k < N; ++k)\r
- {\r
- dst_res_3d.at<float>(0, k) /= dst_res_3d.at<float>(2, k);\r
- dst_res_3d.at<float>(1, k) /= dst_res_3d.at<float>(2, k);\r
- dst_res_3d.at<float>(2, k) = 1.0f;\r
- \r
- float *p = dst_mat_2f.ptr<float>()+2*k;\r
-\r
- dst_mat_3d.at<float>(0, k) = p[0];\r
- dst_mat_3d.at<float>(1, k) = p[1];\r
-\r
- double diff = cv::norm(dst_res_3d.col(k), dst_mat_3d.col(k), NORM_L2); \r
-\r
- if (mask_res[j].at<bool>(k, 0) != (diff <= reproj_threshold))\r
- {\r
- print_information_6(j, N, k, diff, mask_res[j].at<bool>(k, 0));\r
- CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_4);\r
- return; \r
- } \r
-\r
- if (mask.at<bool>(k, 0) && !mask_res[j].at<bool>(k, 0))\r
- {\r
- print_information_7(j, N, k, diff, mask.at<bool>(k, 0), mask_res[j].at<bool>(k, 0));\r
- CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_5);\r
- return;\r
- }\r
-\r
- if (mask_res[j].at<bool>(k, 0))\r
- {\r
- float *a = noise_2f.ptr<float>()+2*k;\r
- dst_mat_3d.at<float>(0, k) -= a[0];\r
- dst_mat_3d.at<float>(1, k) -= a[1];\r
-\r
- cv::Mat noise_2d(2, 1, CV_32F);\r
- noise_2d.at<float>(0, 0) = a[0]; noise_2d.at<float>(1, 0) = a[1];\r
-\r
- for (size_t l = 0; l < COUNT_NORM_TYPES; ++l)\r
- {\r
- diff = cv::norm(dst_res_3d.col(k), dst_mat_3d.col(k), NORM_TYPE[l]);\r
- \r
- if (diff - cv::norm(noise_2d, NORM_TYPE[l]) > max_2diff)\r
- {\r
- print_information_8(j, N, k, l, diff - cv::norm(noise_2d, NORM_TYPE[l])); \r
- CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_DIFF, MESSAGE_RANSAC_DIFF);\r
- return; \r
- }\r
- }\r
- }\r
- }\r
- }\r
+ case CV_RANSAC:\r
+ {\r
+ cv::Mat mask_res [4];\r
+\r
+ Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, CV_RANSAC, reproj_threshold, mask_res[0]),\r
+ cv::findHomography(src_mat_2f, dst_vec, CV_RANSAC, reproj_threshold, mask_res[1]),\r
+ cv::findHomography(src_vec, dst_mat_2f, CV_RANSAC, reproj_threshold, mask_res[2]),\r
+ cv::findHomography(src_vec, dst_vec, CV_RANSAC, reproj_threshold, mask_res[3]) };\r
+\r
+ for (size_t j = 0; j < 4; ++j)\r
+ {\r
+\r
+ if (!check_matrix_size(H_res_64[j]))\r
+ {\r
+ print_information_1(j, N, method, H_res_64[j]);\r
+ CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE, MESSAGE_MATRIX_SIZE);\r
+ return;\r
+ }\r
+\r
+ int code = check_ransac_mask_2(mask, mask_res[j]);\r
+\r
+ if (code)\r
+ {\r
+ print_information_3(j, N, mask_res[j]);\r
+\r
+ switch (code)\r
+ {\r
+ case 1: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_1); break; }\r
+ case 2: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_3); break; }\r
+\r
+ default: break;\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ cv::Mat H_res_32; H_res_64[j].convertTo(H_res_32, CV_32F);\r
+\r
+ cv::Mat dst_res_3d = H_res_32*src_mat_3d;\r
+\r
+ for (size_t k = 0; k < N; ++k)\r
+ {\r
+ dst_res_3d.at<float>(0, k) /= dst_res_3d.at<float>(2, k);\r
+ dst_res_3d.at<float>(1, k) /= dst_res_3d.at<float>(2, k);\r
+ dst_res_3d.at<float>(2, k) = 1.0f;\r
+\r
+ float *p = dst_mat_2f.ptr<float>()+2*k;\r
+\r
+ dst_mat_3d.at<float>(0, k) = p[0];\r
+ dst_mat_3d.at<float>(1, k) = p[1];\r
+\r
+ double diff = cv::norm(dst_res_3d.col(k), dst_mat_3d.col(k), NORM_L2);\r
+\r
+ if (mask_res[j].at<bool>(k, 0) != (diff <= reproj_threshold))\r
+ {\r
+ print_information_6(j, N, k, diff, mask_res[j].at<bool>(k, 0));\r
+ CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_4);\r
+ return;\r
+ }\r
+\r
+ if (mask.at<bool>(k, 0) && !mask_res[j].at<bool>(k, 0))\r
+ {\r
+ print_information_7(j, N, k, diff, mask.at<bool>(k, 0), mask_res[j].at<bool>(k, 0));\r
+ CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_5);\r
+ return;\r
+ }\r
+\r
+ if (mask_res[j].at<bool>(k, 0))\r
+ {\r
+ float *a = noise_2f.ptr<float>()+2*k;\r
+ dst_mat_3d.at<float>(0, k) -= a[0];\r
+ dst_mat_3d.at<float>(1, k) -= a[1];\r
+\r
+ cv::Mat noise_2d(2, 1, CV_32F);\r
+ noise_2d.at<float>(0, 0) = a[0]; noise_2d.at<float>(1, 0) = a[1];\r
+\r
+ for (size_t l = 0; l < COUNT_NORM_TYPES; ++l)\r
+ {\r
+ diff = cv::norm(dst_res_3d.col(k), dst_mat_3d.col(k), NORM_TYPE[l]);\r
+\r
+ if (diff - cv::norm(noise_2d, NORM_TYPE[l]) > max_2diff)\r
+ {\r
+ print_information_8(j, N, k, l, diff - cv::norm(noise_2d, NORM_TYPE[l]));\r
+ CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_DIFF, MESSAGE_RANSAC_DIFF);\r
+ return;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
\r
- continue;\r
- }\r
- \r
- default: continue;\r
- } \r
- }\r
- }\r
+ continue;\r
+ }\r
+\r
+ default: continue;\r
+ }\r
+ }\r
+ }\r
}\r
\r
-TEST(Calib3d_Homography, complex_test) { CV_HomographyTest test; test.safe_run(); }
\ No newline at end of file
+TEST(Calib3d_Homography, accuracy) { CV_HomographyTest test; test.safe_run(); }\r
\r
class CV_CountNonZeroTest: public cvtest::BaseTest\r
{\r
- public:\r
+public:\r
CV_CountNonZeroTest();\r
~CV_CountNonZeroTest();\r
\r
- protected:\r
+protected:\r
void run (int);\r
\r
- private:\r
- float eps_32; \r
- double eps_64; \r
- Mat src;\r
- int current_type;\r
+private:\r
+ float eps_32;\r
+ double eps_64;\r
+ Mat src;\r
+ int current_type;\r
\r
- void generate_src_data(cv::Size size, int type);\r
- void generate_src_data(cv::Size size, int type, int count_non_zero);\r
- void generate_src_stat_data(cv::Size size, int type, int distribution);\r
+ void generate_src_data(cv::Size size, int type);\r
+ void generate_src_data(cv::Size size, int type, int count_non_zero);\r
+ void generate_src_stat_data(cv::Size size, int type, int distribution);\r
\r
- int get_count_non_zero();\r
+ int get_count_non_zero();\r
\r
- void print_information(int right, int result);\r
+ void print_information(int right, int result);\r
};\r
\r
CV_CountNonZeroTest::CV_CountNonZeroTest(): eps_32(1e-8), eps_64(1e-16), src(Mat()), current_type(-1) {}\r
\r
void CV_CountNonZeroTest::generate_src_data(cv::Size size, int type)\r
{\r
- src.create(size, CV_MAKETYPE(type, 1));\r
-\r
- for (size_t j = 0; j < size.width; ++j)\r
- for (size_t i = 0; i < size.height; ++i)\r
- switch (type)\r
- {\r
- case CV_8U: { src.at<uchar>(i, j) = cv::randu<uchar>(); break; }\r
- case CV_8S: { src.at<char>(i, j) = cv::randu<uchar>() - 128; break; }\r
- case CV_16U: { src.at<ushort>(i, j) = cv::randu<ushort>(); break; }\r
- case CV_16S: { src.at<short>(i, j) = cv::randu<short>(); break; }\r
- case CV_32S: { src.at<int>(i, j) = cv::randu<int>(); break; }\r
- case CV_32F: { src.at<float>(i, j) = cv::randu<float>(); break; }\r
- case CV_64F: { src.at<double>(i, j) = cv::randu<double>(); break; }\r
- default: break;\r
- }\r
+ src.create(size, CV_MAKETYPE(type, 1));\r
+\r
+ for (int j = 0; j < size.width; ++j)\r
+ for (int i = 0; i < size.height; ++i)\r
+ switch (type)\r
+ {\r
+ case CV_8U: { src.at<uchar>(i, j) = cv::randu<uchar>(); break; }\r
+ case CV_8S: { src.at<char>(i, j) = cv::randu<uchar>() - 128; break; }\r
+ case CV_16U: { src.at<ushort>(i, j) = cv::randu<ushort>(); break; }\r
+ case CV_16S: { src.at<short>(i, j) = cv::randu<short>(); break; }\r
+ case CV_32S: { src.at<int>(i, j) = cv::randu<int>(); break; }\r
+ case CV_32F: { src.at<float>(i, j) = cv::randu<float>(); break; }\r
+ case CV_64F: { src.at<double>(i, j) = cv::randu<double>(); break; }\r
+ default: break;\r
+ }\r
}\r
\r
void CV_CountNonZeroTest::generate_src_data(cv::Size size, int type, int count_non_zero)\r
{\r
- src = Mat::zeros(size, CV_MAKETYPE(type, 1));\r
- \r
- int n = 0; RNG& rng = ts->get_rng();\r
-\r
- while (n < count_non_zero)\r
- {\r
- size_t i = rng.next()%size.height, j = rng.next()%size.width;\r
- \r
- switch (type)\r
- {\r
- case CV_8U: { if (!src.at<uchar>(i, j)) {src.at<uchar>(i, j) = cv::randu<uchar>(); n += (src.at<uchar>(i, j) > 0);} break; }\r
- case CV_8S: { if (!src.at<char>(i, j)) {src.at<char>(i, j) = cv::randu<uchar>() - 128; n += abs(sign(src.at<char>(i, j)));} break; }\r
- case CV_16U: { if (!src.at<ushort>(i, j)) {src.at<ushort>(i, j) = cv::randu<ushort>(); n += (src.at<ushort>(i, j) > 0);} break; }\r
- case CV_16S: { if (!src.at<short>(i, j)) {src.at<short>(i, j) = cv::randu<short>(); n += abs(sign(src.at<short>(i, j)));} break; }\r
- case CV_32S: { if (!src.at<int>(i, j)) {src.at<int>(i, j) = cv::randu<int>(); n += abs(sign(src.at<int>(i, j)));} break; }\r
- case CV_32F: { if (fabs(src.at<float>(i, j)) <= eps_32) {src.at<float>(i, j) = cv::randu<float>(); n += (fabs(src.at<float>(i, j)) > eps_32);} break; }\r
- case CV_64F: { if (fabs(src.at<double>(i, j)) <= eps_64) {src.at<double>(i, j) = cv::randu<double>(); n += (fabs(src.at<double>(i, j)) > eps_64);} break; }\r
-\r
- default: break;\r
- }\r
- }\r
- \r
+ src = Mat::zeros(size, CV_MAKETYPE(type, 1));\r
+\r
+ int n = 0; RNG& rng = ts->get_rng();\r
+\r
+ while (n < count_non_zero)\r
+ {\r
+ size_t i = rng.next()%size.height, j = rng.next()%size.width;\r
+\r
+ switch (type)\r
+ {\r
+ case CV_8U: { if (!src.at<uchar>(i, j)) {src.at<uchar>(i, j) = cv::randu<uchar>(); n += (src.at<uchar>(i, j) > 0);} break; }\r
+ case CV_8S: { if (!src.at<char>(i, j)) {src.at<char>(i, j) = cv::randu<uchar>() - 128; n += abs(sign(src.at<char>(i, j)));} break; }\r
+ case CV_16U: { if (!src.at<ushort>(i, j)) {src.at<ushort>(i, j) = cv::randu<ushort>(); n += (src.at<ushort>(i, j) > 0);} break; }\r
+ case CV_16S: { if (!src.at<short>(i, j)) {src.at<short>(i, j) = cv::randu<short>(); n += abs(sign(src.at<short>(i, j)));} break; }\r
+ case CV_32S: { if (!src.at<int>(i, j)) {src.at<int>(i, j) = cv::randu<int>(); n += abs(sign(src.at<int>(i, j)));} break; }\r
+ case CV_32F: { if (fabs(src.at<float>(i, j)) <= eps_32) {src.at<float>(i, j) = cv::randu<float>(); n += (fabs(src.at<float>(i, j)) > eps_32);} break; }\r
+ case CV_64F: { if (fabs(src.at<double>(i, j)) <= eps_64) {src.at<double>(i, j) = cv::randu<double>(); n += (fabs(src.at<double>(i, j)) > eps_64);} break; }\r
+\r
+ default: break;\r
+ }\r
+ }\r
+\r
}\r
\r
void CV_CountNonZeroTest::generate_src_stat_data(cv::Size size, int type, int distribution)\r
{\r
- src.create(size, CV_MAKETYPE(type, 1));\r
+ src.create(size, CV_MAKETYPE(type, 1));\r
\r
- double mean = 0.0, sigma = 1.0;\r
- double left = -1.0, right = 1.0;\r
+ double mean = 0.0, sigma = 1.0;\r
+ double left = -1.0, right = 1.0;\r
\r
- RNG& rng = ts->get_rng();\r
+ RNG& rng = ts->get_rng();\r
\r
- if (distribution == RNG::NORMAL) \r
- rng.fill(src, RNG::NORMAL, Scalar::all(mean), Scalar::all(sigma));\r
- else if (distribution == RNG::UNIFORM)\r
- rng.fill(src, RNG::UNIFORM, Scalar::all(left), Scalar::all(right));\r
+ if (distribution == RNG::NORMAL)\r
+ rng.fill(src, RNG::NORMAL, Scalar::all(mean), Scalar::all(sigma));\r
+ else if (distribution == RNG::UNIFORM)\r
+ rng.fill(src, RNG::UNIFORM, Scalar::all(left), Scalar::all(right));\r
}\r
\r
int CV_CountNonZeroTest::get_count_non_zero()\r
{\r
- int result = 0;\r
+ int result = 0;\r
+\r
+ for (int i = 0; i < src.rows; ++i)\r
+ for (int j = 0; j < src.cols; ++j)\r
\r
- for (size_t i = 0; i < src.rows; ++i)\r
- for (size_t j = 0; j < src.cols; ++j)\r
+ if (current_type == CV_8U) result += (src.at<uchar>(i, j) > 0);\r
\r
- if (current_type == CV_8U) result += (src.at<uchar>(i, j) > 0);\r
- \r
- else if (current_type == CV_8S) result += abs(sign(src.at<char>(i, j))); \r
+ else if (current_type == CV_8S) result += abs(sign(src.at<char>(i, j)));\r
\r
- else if (current_type == CV_16U) result += (src.at<ushort>(i, j) > 0); \r
+ else if (current_type == CV_16U) result += (src.at<ushort>(i, j) > 0);\r
\r
- else if (current_type == CV_16S) result += abs(sign(src.at<short>(i, j)));\r
+ else if (current_type == CV_16S) result += abs(sign(src.at<short>(i, j)));\r
\r
- else if (current_type == CV_32S) result += abs(sign(src.at<int>(i, j)));\r
+ else if (current_type == CV_32S) result += abs(sign(src.at<int>(i, j)));\r
\r
- else if (current_type == CV_32F) result += (fabs(src.at<float>(i, j)) > eps_32);\r
+ else if (current_type == CV_32F) result += (fabs(src.at<float>(i, j)) > eps_32);\r
\r
- else result += (fabs(src.at<double>(i, j)) > eps_64);\r
+ else result += (fabs(src.at<double>(i, j)) > eps_64);\r
\r
- return result;\r
+ return result;\r
}\r
\r
void CV_CountNonZeroTest::print_information(int right, int result)\r
{\r
- cout << endl; cout << "Checking for the work of countNonZero function..." << endl; cout << endl;\r
- cout << "Type of Mat: "; \r
- switch (current_type)\r
- {\r
- case 0: {cout << "CV_8U"; break;} \r
- case 1: {cout << "CV_8S"; break;}\r
- case 2: {cout << "CV_16U"; break;}\r
- case 3: {cout << "CV_16S"; break;}\r
- case 4: {cout << "CV_32S"; break;}\r
- case 5: {cout << "CV_32F"; break;}\r
- case 6: {cout << "CV_64F"; break;}\r
- default: break;\r
- }\r
- cout << endl;\r
- cout << "Number of rows: " << src.rows << " Number of cols: " << src.cols << endl;\r
- cout << "True count non zero elements: " << right << " Result: " << result << endl; \r
- cout << endl;\r
+ cout << endl; cout << "Checking for the work of countNonZero function..." << endl; cout << endl;\r
+ cout << "Type of Mat: ";\r
+ switch (current_type)\r
+ {\r
+ case 0: {cout << "CV_8U"; break;}\r
+ case 1: {cout << "CV_8S"; break;}\r
+ case 2: {cout << "CV_16U"; break;}\r
+ case 3: {cout << "CV_16S"; break;}\r
+ case 4: {cout << "CV_32S"; break;}\r
+ case 5: {cout << "CV_32F"; break;}\r
+ case 6: {cout << "CV_64F"; break;}\r
+ default: break;\r
+ }\r
+ cout << endl;\r
+ cout << "Number of rows: " << src.rows << " Number of cols: " << src.cols << endl;\r
+ cout << "True count non zero elements: " << right << " Result: " << result << endl;\r
+ cout << endl;\r
}\r
\r
void CV_CountNonZeroTest::run(int)\r
{\r
- const size_t N = 1500;\r
-\r
- for (int k = 1; k <= 3; ++k)\r
- for (size_t i = 0; i < N; ++i)\r
- {\r
- RNG& rng = ts->get_rng();\r
-\r
- int w = rng.next()%MAX_WIDTH + 1, h = rng.next()%MAX_HEIGHT + 1;\r
-\r
- current_type = rng.next()%7;\r
-\r
- switch (k)\r
- {\r
- case 1: { \r
- generate_src_data(Size(w, h), current_type);\r
- int right = get_count_non_zero(), result = countNonZero(src);\r
- if (result != right)\r
- {\r
- cout << "Number of experiment: " << i << endl;\r
- cout << "Method of data generation: RANDOM" << endl;\r
- print_information(right, result);\r
- CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);\r
- return;\r
- }\r
-\r
- break;\r
- }\r
-\r
- case 2: {\r
- int count_non_zero = rng.next()%(w*h);\r
- generate_src_data(Size(w, h), current_type, count_non_zero);\r
- int result = countNonZero(src);\r
- if (result != count_non_zero)\r
- {\r
- cout << "Number of experiment: " << i << endl;\r
- cout << "Method of data generation: HALF-RANDOM" << endl;\r
- print_information(count_non_zero, result);\r
- CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);\r
- return;\r
- }\r
-\r
- break;\r
- }\r
-\r
- case 3: {\r
- int distribution = cv::randu<uchar>()%2;\r
- generate_src_stat_data(Size(w, h), current_type, distribution);\r
- int right = get_count_non_zero(), result = countNonZero(src);\r
- if (right != result)\r
- {\r
- cout << "Number of experiment: " << i << endl;\r
- cout << "Method of data generation: STATISTIC" << endl;\r
- print_information(right, result);\r
- CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);\r
- return;\r
- }\r
-\r
- break;\r
- }\r
-\r
- default: break;\r
- }\r
- }\r
+ const size_t N = 1500;\r
+\r
+ for (int k = 1; k <= 3; ++k)\r
+ for (size_t i = 0; i < N; ++i)\r
+ {\r
+ RNG& rng = ts->get_rng();\r
+\r
+ int w = rng.next()%MAX_WIDTH + 1, h = rng.next()%MAX_HEIGHT + 1;\r
+\r
+ current_type = rng.next()%7;\r
+\r
+ switch (k)\r
+ {\r
+ case 1: {\r
+ generate_src_data(Size(w, h), current_type);\r
+ int right = get_count_non_zero(), result = countNonZero(src);\r
+ if (result != right)\r
+ {\r
+ cout << "Number of experiment: " << i << endl;\r
+ cout << "Method of data generation: RANDOM" << endl;\r
+ print_information(right, result);\r
+ CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);\r
+ return;\r
+ }\r
+\r
+ break;\r
+ }\r
+\r
+ case 2: {\r
+ int count_non_zero = rng.next()%(w*h);\r
+ generate_src_data(Size(w, h), current_type, count_non_zero);\r
+ int result = countNonZero(src);\r
+ if (result != count_non_zero)\r
+ {\r
+ cout << "Number of experiment: " << i << endl;\r
+ cout << "Method of data generation: HALF-RANDOM" << endl;\r
+ print_information(count_non_zero, result);\r
+ CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);\r
+ return;\r
+ }\r
+\r
+ break;\r
+ }\r
+\r
+ case 3: {\r
+ int distribution = cv::randu<uchar>()%2;\r
+ generate_src_stat_data(Size(w, h), current_type, distribution);\r
+ int right = get_count_non_zero(), result = countNonZero(src);\r
+ if (right != result)\r
+ {\r
+ cout << "Number of experiment: " << i << endl;\r
+ cout << "Method of data generation: STATISTIC" << endl;\r
+ print_information(right, result);\r
+ CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);\r
+ return;\r
+ }\r
+\r
+ break;\r
+ }\r
+\r
+ default: break;\r
+ }\r
+ }\r
}\r
\r
-// TEST (Core_CountNonZero, accuracy) { CV_CountNonZeroTest test; test.safe_run(); }
\ No newline at end of file
+// TEST (Core_CountNonZero, accuracy) { CV_CountNonZeroTest test; test.safe_run(); }\r
#define CORE_EIGEN_ERROR_ORTHO 4\r
#define CORE_EIGEN_ERROR_ORDER 5\r
\r
+#define MESSAGE_ERROR_COUNT "Matrix of eigen values must have the same rows as source matrix and 1 column."\r
+#define MESSAGE_ERROR_SIZE "Source matrix and matrix of eigen vectors must have the same sizes."\r
+#define MESSAGE_ERROR_DIFF_1 "Accurasy of eigen values computing less than required."\r
+#define MESSAGE_ERROR_DIFF_2 "Accuracy of eigen vectors computing less than required."\r
+#define MESSAGE_ERROR_ORTHO "Matrix of eigen vectors is not orthogonal."\r
+#define MESSAGE_ERROR_ORDER "Eigen values are not sorted in ascending order."\r
+\r
+const size_t COUNT_NORM_TYPES = 3;\r
+const size_t NORM_TYPE[COUNT_NORM_TYPES] = {cv::NORM_L1, cv::NORM_L2, cv::NORM_INF};\r
+\r
+enum TASK_TYPE_EIGEN {VALUES, VECTORS};\r
+\r
class Core_EigenTest: public cvtest::BaseTest\r
{\r
- public: \r
+public:\r
\r
- Core_EigenTest();\r
+ Core_EigenTest();\r
~Core_EigenTest();\r
\r
- protected:\r
+protected:\r
\r
- bool test_values(const cv::Mat& src); // complex test for eigen without vectors\r
- bool check_full(int type); // compex test for symmetric matrix\r
- virtual void run (int) = 0; // main testing method\r
-\r
- private:\r
- \r
- float eps_val_32, eps_vec_32;\r
- float eps_val_64, eps_vec_64;\r
- bool check_pair_count(const cv::Mat& src, const cv::Mat& evalues, int low_index = -1, int high_index = -1);\r
- bool check_pair_count(const cv::Mat& src, const cv::Mat& evalues, const cv::Mat& evectors, int low_index = -1, int high_index = -1);\r
- bool check_pairs_order(const cv::Mat& eigen_values); // checking order of eigen values & vectors (it should be none up)\r
- bool check_orthogonality(const cv::Mat& U); // checking is matrix of eigen vectors orthogonal\r
- bool test_pairs(const cv::Mat& src); // complex test for eigen with vectors\r
+ bool test_values(const cv::Mat& src); // complex test for eigen without vectors\r
+ bool check_full(int type); // compex test for symmetric matrix\r
+ virtual void run (int) = 0; // main testing method\r
+\r
+private:\r
+\r
+ float eps_val_32, eps_vec_32;\r
+ float eps_val_64, eps_vec_64;\r
+ bool check_pair_count(const cv::Mat& src, const cv::Mat& evalues, int low_index = -1, int high_index = -1);\r
+ bool check_pair_count(const cv::Mat& src, const cv::Mat& evalues, const cv::Mat& evectors, int low_index = -1, int high_index = -1);\r
+ bool check_pairs_order(const cv::Mat& eigen_values); // checking order of eigen values & vectors (it should be none up)\r
+ bool check_orthogonality(const cv::Mat& U); // checking is matrix of eigen vectors orthogonal\r
+ bool test_pairs(const cv::Mat& src); // complex test for eigen with vectors\r
+\r
+ void print_information(const size_t norm_idx, const cv::Mat& src, double diff, double max_diff);\r
};\r
\r
class Core_EigenTest_Scalar : public Core_EigenTest\r
{\r
- public:\r
- Core_EigenTest_Scalar() : Core_EigenTest() {}\r
- ~Core_EigenTest_Scalar();\r
- virtual void run(int) = 0;\r
+public:\r
+ Core_EigenTest_Scalar() : Core_EigenTest() {}\r
+ ~Core_EigenTest_Scalar();\r
+\r
+ virtual void run(int) = 0;\r
};\r
\r
class Core_EigenTest_Scalar_32 : public Core_EigenTest_Scalar\r
{\r
- public:\r
- Core_EigenTest_Scalar_32() : Core_EigenTest_Scalar() {}\r
- ~Core_EigenTest_Scalar_32();\r
+public:\r
+ Core_EigenTest_Scalar_32() : Core_EigenTest_Scalar() {}\r
+ ~Core_EigenTest_Scalar_32();\r
\r
- void run(int);\r
+ void run(int);\r
};\r
\r
class Core_EigenTest_Scalar_64 : public Core_EigenTest_Scalar\r
{\r
- public:\r
+public:\r
Core_EigenTest_Scalar_64() : Core_EigenTest_Scalar() {}\r
~Core_EigenTest_Scalar_64();\r
void run(int);\r
\r
class Core_EigenTest_32 : public Core_EigenTest\r
{\r
- public:\r
+public:\r
Core_EigenTest_32(): Core_EigenTest() {}\r
~Core_EigenTest_32() {}\r
void run(int);\r
\r
class Core_EigenTest_64 : public Core_EigenTest\r
{\r
- public:\r
- Core_EigenTest_64(): Core_EigenTest() {}\r
- ~Core_EigenTest_64() {}\r
- void run(int);\r
+public:\r
+ Core_EigenTest_64(): Core_EigenTest() {}\r
+ ~Core_EigenTest_64() {}\r
+ void run(int);\r
};\r
\r
Core_EigenTest_Scalar::~Core_EigenTest_Scalar() {}\r
\r
void Core_EigenTest_Scalar_32::run(int) \r
{\r
- float value = cv::randu<float>();\r
- cv::Mat src(1, 1, CV_32FC1, Scalar::all((float)value));\r
- test_values(src);\r
- src.~Mat();\r
+ float value = cv::randu<float>();\r
+ cv::Mat src(1, 1, CV_32FC1, Scalar::all((float)value));\r
+ test_values(src);\r
+ src.~Mat();\r
}\r
\r
void Core_EigenTest_Scalar_64::run(int)\r
{\r
- float value = cv::randu<float>();\r
- cv::Mat src(1, 1, CV_64FC1, Scalar::all((double)value));\r
- test_values(src);\r
- src.~Mat();\r
+ float value = cv::randu<float>();\r
+ cv::Mat src(1, 1, CV_64FC1, Scalar::all((double)value));\r
+ test_values(src);\r
+ src.~Mat();\r
}\r
\r
void Core_EigenTest_32::run(int) { check_full(CV_32FC1); }\r
\r
bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues, int low_index, int high_index)\r
{\r
- int n = src.rows, s = sign(high_index);\r
- if (!( (evalues.rows == n - max<int>(0, low_index) - ((int)((n/2.0)*(s*s-s)) + (1+s-s*s)*(n - (high_index+1)))) && (evalues.cols == 1)))\r
- { \r
- std::cout << "Checking sizes of eigen values matrix " << evalues << "..." << endl;\r
- CV_Error(CORE_EIGEN_ERROR_COUNT, "Matrix of eigen values must have the same rows as source matrix and 1 column."); \r
- return false; \r
- }\r
- return true;\r
+ int n = src.rows, s = sign(high_index);\r
+ if (!( (evalues.rows == n - max<int>(0, low_index) - ((int)((n/2.0)*(s*s-s)) + (1+s-s*s)*(n - (high_index+1)))) && (evalues.cols == 1)))\r
+ {\r
+ std::cout << endl; std::cout << "Checking sizes of eigen values matrix " << evalues << "..." << endl;\r
+ std::cout << "Number of rows: " << evalues.rows << " Number of cols: " << evalues.cols << endl;\r
+ std:: cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl;\r
+ CV_Error(CORE_EIGEN_ERROR_COUNT, MESSAGE_ERROR_COUNT);\r
+ return false;\r
+ }\r
+ return true;\r
}\r
\r
bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues, const cv::Mat& evectors, int low_index, int high_index)\r
{\r
- int n = src.rows, s = sign(high_index);\r
- int right_eigen_pair_count = n - max<int>(0, low_index) - ((int)((n/2.0)*(s*s-s)) + (1+s-s*s)*(n - (high_index+1)));\r
-\r
- if (!((evectors.rows == right_eigen_pair_count) && (evectors.cols == right_eigen_pair_count)))\r
- { \r
- std::cout << "Checking sizes of eigen vectors matrix " << evectors << "..." << endl;\r
- CV_Error (CORE_EIGEN_ERROR_SIZE, "Source matrix and matrix of eigen vectors must have the same sizes."); \r
- return false; \r
- }\r
-\r
- if (!((evalues.rows == right_eigen_pair_count) && (evalues.cols == 1)))\r
- {\r
- std::cout << "Checking sizes of eigen values matrix " << evalues << "..." << endl;\r
- CV_Error (CORE_EIGEN_ERROR_COUNT, "Matrix of eigen values must have the same rows as source matrix and 1 column."); \r
- return false; \r
- }\r
-\r
- return true;\r
+ int n = src.rows, s = sign(high_index);\r
+ int right_eigen_pair_count = n - max<int>(0, low_index) - ((int)((n/2.0)*(s*s-s)) + (1+s-s*s)*(n - (high_index+1)));\r
+\r
+ if (!((evectors.rows == right_eigen_pair_count) && (evectors.cols == right_eigen_pair_count)))\r
+ {\r
+ std::cout << endl; std::cout << "Checking sizes of eigen vectors matrix " << evectors << "..." << endl;\r
+ std::cout << "Number of rows: " << evectors.rows << " Number of cols: " << evectors.cols << endl;\r
+ std:: cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl;\r
+ CV_Error (CORE_EIGEN_ERROR_SIZE, MESSAGE_ERROR_SIZE);\r
+ return false;\r
+ }\r
+\r
+ if (!((evalues.rows == right_eigen_pair_count) && (evalues.cols == 1)))\r
+ {\r
+ std::cout << endl; std::cout << "Checking sizes of eigen values matrix " << evalues << "..." << endl;\r
+ std::cout << "Number of rows: " << evalues.rows << " Number of cols: " << evalues.cols << endl;\r
+ std:: cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl;\r
+ CV_Error (CORE_EIGEN_ERROR_COUNT, MESSAGE_ERROR_COUNT);\r
+ return false;\r
+ }\r
+\r
+ return true;\r
}\r
\r
-bool Core_EigenTest::check_orthogonality(const cv::Mat& U)\r
+void Core_EigenTest::print_information(const size_t norm_idx, const cv::Mat& src, double diff, double max_diff)\r
{\r
- int type = U.type();\r
- double eps_vec = type == CV_32FC1 ? eps_vec_32 : eps_vec_64;\r
- cv::Mat UUt; cv::mulTransposed(U, UUt, false); \r
-\r
- cv::Mat E = Mat::eye(U.rows, U.cols, type);\r
- \r
- double diff_L1 = cv::norm(UUt, E, NORM_L1);\r
- double diff_L2 = cv::norm(UUt, E, NORM_L2);\r
- double diff_INF = cv::norm(UUt, E, NORM_INF);\r
-\r
- if (diff_L1 > eps_vec) { std::cout << "Checking orthogonality of matrix " << U << "..." << endl; CV_Error(CORE_EIGEN_ERROR_ORTHO, "Matrix of eigen vectors is not orthogonal."); return false; }\r
- if (diff_L2 > eps_vec) { std::cout << "Checking orthogonality of matrix " << U << "..." << endl; CV_Error(CORE_EIGEN_ERROR_ORTHO, "Matrix of eigen vectors is not orthogonal."); return false; }\r
- if (diff_INF > eps_vec) { std::cout << "Checking orthogonality of matrix " << U << "..." << endl; CV_Error(CORE_EIGEN_ERROR_ORTHO, "Matrix of eigen vectors is not orthogonal."); return false; }\r
+ switch (NORM_TYPE[norm_idx])\r
+ {\r
+ case cv::NORM_L1: {std::cout << "L1"; break;}\r
+ case cv::NORM_L2: {std::cout << "L2"; break;}\r
+ case cv::NORM_INF: {std::cout << "INF"; break;}\r
+ default: break;\r
+ }\r
+\r
+ cout << "-criteria... " << endl;\r
+ cout << "Source size: " << src.rows << " * " << src.cols << endl;\r
+ cout << "Difference between original eigen vectors matrix and result: " << diff << endl;\r
+ cout << "Maximum allowed difference: " << max_diff << endl; cout << endl;\r
+}\r
\r
- return true;\r
+bool Core_EigenTest::check_orthogonality(const cv::Mat& U)\r
+{\r
+ int type = U.type();\r
+ double eps_vec = type == CV_32FC1 ? eps_vec_32 : eps_vec_64;\r
+ cv::Mat UUt; cv::mulTransposed(U, UUt, false);\r
+\r
+ cv::Mat E = Mat::eye(U.rows, U.cols, type);\r
+\r
+ for (size_t i = 0; i < COUNT_NORM_TYPES; ++i)\r
+ {\r
+ double diff = cv::norm(UUt, E, NORM_TYPE[i]);\r
+ if (diff > eps_vec)\r
+ {\r
+ std::cout << endl; std::cout << "Checking orthogonality of matrix " << U << ": ";\r
+ print_information(i, U, diff, eps_vec);\r
+ CV_Error(CORE_EIGEN_ERROR_ORTHO, MESSAGE_ERROR_ORTHO);\r
+ return false;\r
+ }\r
+ }\r
+\r
+ return true;\r
}\r
\r
bool Core_EigenTest::check_pairs_order(const cv::Mat& eigen_values)\r
{\r
- switch (eigen_values.type())\r
- {\r
- case CV_32FC1:\r
- {\r
- for (int i = 0; i < eigen_values.total() - 1; ++i)\r
- if (!(eigen_values.at<float>(i, 0) > eigen_values.at<float>(i+1, 0)))\r
- {\r
- std::cout << "Checking order of eigen values vector " << eigen_values << "..." << endl;\r
- CV_Error(CORE_EIGEN_ERROR_ORDER, "Eigen values are not sorted in ascending order.");\r
- return false;\r
- }\r
-\r
- break;\r
- }\r
- \r
- case CV_64FC1:\r
- {\r
- for (int i = 0; i < eigen_values.total() - 1; ++i)\r
- if (!(eigen_values.at<double>(i, 0) > eigen_values.at<double>(i+1, 0)))\r
- {\r
- std::cout << "Checking order of eigen values vector " << eigen_values << "..." << endl;\r
- CV_Error(CORE_EIGEN_ERROR_ORDER, "Eigen values are not sorted in ascending order.");\r
- return false;\r
- }\r
-\r
- break;\r
- }\r
-\r
- default:;\r
- }\r
-\r
- return true;\r
+ switch (eigen_values.type())\r
+ {\r
+ case CV_32FC1:\r
+ {\r
+ for (size_t i = 0; i < eigen_values.total() - 1; ++i)\r
+ if (!(eigen_values.at<float>(i, 0) > eigen_values.at<float>(i+1, 0)))\r
+ {\r
+ std::cout << endl; std::cout << "Checking order of eigen values vector " << eigen_values << "..." << endl;\r
+ std::cout << "Pair of indexes with non ascending of eigen values: (" << i << ", " << i+1 << ")." << endl;\r
+ std::cout << endl;\r
+ CV_Error(CORE_EIGEN_ERROR_ORDER, MESSAGE_ERROR_ORDER);\r
+ return false;\r
+ }\r
+\r
+ break;\r
+ }\r
+\r
+ case CV_64FC1:\r
+ {\r
+ for (size_t i = 0; i < eigen_values.total() - 1; ++i)\r
+ if (!(eigen_values.at<double>(i, 0) > eigen_values.at<double>(i+1, 0)))\r
+ {\r
+ std::cout << endl; std::cout << "Checking order of eigen values vector " << eigen_values << "..." << endl;\r
+ std::cout << "Pair of indexes with non ascending of eigen values: (" << i << ", " << i+1 << ")." << endl;\r
+ std::cout << endl;\r
+ CV_Error(CORE_EIGEN_ERROR_ORDER, "Eigen values are not sorted in ascending order.");\r
+ return false;\r
+ }\r
+\r
+ break;\r
+ }\r
+\r
+ default:;\r
+ }\r
+\r
+ return true;\r
}\r
\r
bool Core_EigenTest::test_pairs(const cv::Mat& src)\r
{\r
- int type = src.type();\r
- double eps_vec = type == CV_32FC1 ? eps_vec_32 : eps_vec_64;\r
+ int type = src.type();\r
+ double eps_vec = type == CV_32FC1 ? eps_vec_32 : eps_vec_64;\r
+\r
+ cv::Mat eigen_values, eigen_vectors;\r
\r
- cv::Mat eigen_values, eigen_vectors;\r
- \r
- cv::eigen(src, true, eigen_values, eigen_vectors);\r
+ cv::eigen(src, true, eigen_values, eigen_vectors);\r
\r
- if (!check_pair_count(src, eigen_values, eigen_vectors)) return false;\r
+ if (!check_pair_count(src, eigen_values, eigen_vectors)) return false;\r
\r
- if (!check_orthogonality (eigen_vectors)) return false;\r
+ if (!check_orthogonality (eigen_vectors)) return false;\r
\r
- if (!check_pairs_order(eigen_values)) return false;\r
+ if (!check_pairs_order(eigen_values)) return false;\r
\r
- cv::Mat eigen_vectors_t; cv::transpose(eigen_vectors, eigen_vectors_t);\r
+ cv::Mat eigen_vectors_t; cv::transpose(eigen_vectors, eigen_vectors_t);\r
\r
- cv::Mat src_evec(src.rows, src.cols, type);\r
- src_evec = src*eigen_vectors_t; \r
+ cv::Mat src_evec(src.rows, src.cols, type);\r
+ src_evec = src*eigen_vectors_t;\r
\r
- cv::Mat eval_evec(src.rows, src.cols, type);\r
+ cv::Mat eval_evec(src.rows, src.cols, type);\r
\r
- switch (type)\r
- { \r
- case CV_32FC1:\r
- {\r
- for (size_t i = 0; i < src.cols; ++i)\r
- {\r
- cv::Mat tmp = eigen_values.at<float>(i, 0) * eigen_vectors_t.col(i); \r
- for (size_t j = 0; j < src.rows; ++j) eval_evec.at<float>(j, i) = tmp.at<float>(j, 0); \r
- }\r
+ switch (type)\r
+ {\r
+ case CV_32FC1:\r
+ {\r
+ for (int i = 0; i < src.cols; ++i)\r
+ {\r
+ cv::Mat tmp = eigen_values.at<float>(i, 0) * eigen_vectors_t.col(i);\r
+ for (int j = 0; j < src.rows; ++j) eval_evec.at<float>(j, i) = tmp.at<float>(j, 0);\r
+ }\r
\r
- break;\r
- }\r
- \r
- case CV_64FC1:\r
- {\r
- for (size_t i = 0; i < src.cols; ++i)\r
- {\r
- cv::Mat tmp = eigen_values.at<double>(i, 0) * eigen_vectors_t.col(i); \r
- for (size_t j = 0; j < src.rows; ++j) eval_evec.at<double>(j, i) = tmp.at<double>(j, 0); \r
- }\r
+ break;\r
+ }\r
\r
- break; \r
- }\r
+ case CV_64FC1:\r
+ {\r
+ for (int i = 0; i < src.cols; ++i)\r
+ {\r
+ cv::Mat tmp = eigen_values.at<double>(i, 0) * eigen_vectors_t.col(i);\r
+ for (int j = 0; j < src.rows; ++j) eval_evec.at<double>(j, i) = tmp.at<double>(j, 0);\r
+ }\r
\r
- default:;\r
- }\r
+ break;\r
+ }\r
\r
- cv::Mat disparity = src_evec - eval_evec;\r
+ default:;\r
+ }\r
\r
- double diff_L1 = cv::norm(disparity, NORM_L1);\r
- double diff_L2 = cv::norm(disparity, NORM_L2);\r
- double diff_INF = cv::norm(disparity, NORM_INF);\r
+ cv::Mat disparity = src_evec - eval_evec;\r
\r
- if (diff_L1 > eps_vec) { std::cout << "Checking accuracy of eigen vectors computing for matrix " << src << ": L1-criteria..." << endl; CV_Error(CORE_EIGEN_ERROR_DIFF, "Accuracy of eigen vectors computing less than required."); return false; }\r
- if (diff_L2 > eps_vec) { std::cout << "Checking accuracy of eigen vectors computing for matrix " << src << ": L2-criteria..." << endl; CV_Error(CORE_EIGEN_ERROR_DIFF, "Accuracy of eigen vectors computing less than required."); return false; }\r
- if (diff_INF > eps_vec) { std::cout << "Checking accuracy of eigen vectors computing for matrix " << src << ": INF-criteria..." << endl; CV_Error(CORE_EIGEN_ERROR_DIFF, "Accuracy of eigen vectors computing less than required."); return false; }\r
+ for (size_t i = 0; i < COUNT_NORM_TYPES; ++i)\r
+ {\r
+ double diff = cv::norm(disparity, NORM_TYPE[i]);\r
+ if (diff > eps_vec)\r
+ {\r
+ std::cout << endl; std::cout << "Checking accuracy of eigen vectors computing for matrix " << src << ": ";\r
+ print_information(i, src, diff, eps_vec);\r
+ CV_Error(CORE_EIGEN_ERROR_DIFF, MESSAGE_ERROR_DIFF_2);\r
+ return false;\r
+ }\r
+ }\r
\r
- return true;\r
+ return true;\r
}\r
\r
bool Core_EigenTest::test_values(const cv::Mat& src)\r
{\r
- int type = src.type();\r
- double eps_val = type == CV_32FC1 ? eps_val_32 : eps_val_64; \r
+ int type = src.type();\r
+ double eps_val = type == CV_32FC1 ? eps_val_32 : eps_val_64;\r
\r
- cv::Mat eigen_values_1, eigen_values_2, eigen_vectors;\r
+ cv::Mat eigen_values_1, eigen_values_2, eigen_vectors;\r
\r
- if (!test_pairs(src)) return false;\r
+ if (!test_pairs(src)) return false;\r
\r
- cv::eigen(src, true, eigen_values_1, eigen_vectors);\r
- cv::eigen(src, false, eigen_values_2, eigen_vectors);\r
+ cv::eigen(src, true, eigen_values_1, eigen_vectors);\r
+ cv::eigen(src, false, eigen_values_2, eigen_vectors);\r
\r
- if (!check_pair_count(src, eigen_values_2)) return false;\r
+ if (!check_pair_count(src, eigen_values_2)) return false;\r
\r
- double diff_L1 = cv::norm(eigen_values_1, eigen_values_2, NORM_L1);\r
- double diff_L2 = cv::norm(eigen_values_1, eigen_values_2, NORM_L2); \r
- double diff_INF = cv::norm(eigen_values_1, eigen_values_2, NORM_INF); \r
- \r
- if (diff_L1 > eps_val) { std::cout << "Checking accuracy of eigen values computing for matrix " << src << ": L1-criteria..." << endl; CV_Error(CORE_EIGEN_ERROR_DIFF, "Accuracy of eigen values computing less than required."); return false; } \r
- if (diff_L2 > eps_val) { std::cout << "Checking accuracy of eigen values computing for matrix " << src << ": L2-criteria..." << endl; CV_Error(CORE_EIGEN_ERROR_DIFF, "Accuracy of eigen vectors computing less than required."); return false; }\r
- if (diff_INF > eps_val) { std::cout << "Checking accuracy of eigen values computing for matrix " << src << ": INF-criteria..." << endl; CV_Error(CORE_EIGEN_ERROR_DIFF, "Accuracy of eigen vectors computing less than required."); return false; }\r
+ for (size_t i = 0; i < COUNT_NORM_TYPES; ++i)\r
+ {\r
+ double diff = cv::norm(eigen_values_1, eigen_values_2, NORM_TYPE[i]);\r
+ if (diff > eps_val)\r
+ {\r
+ std::cout << endl; std::cout << "Checking accuracy of eigen values computing for matrix " << src << ": ";\r
+ print_information(i, src, diff, eps_val);\r
+ CV_Error(CORE_EIGEN_ERROR_DIFF, MESSAGE_ERROR_DIFF_1);\r
+ return false;\r
+ }\r
+ }\r
\r
- return true;\r
+ return true;\r
}\r
\r
bool Core_EigenTest::check_full(int type)\r
{\r
- const int MATRIX_COUNT = 500;\r
- const int MAX_DEGREE = 7;\r
+ const int MATRIX_COUNT = 500;\r
+ const int MAX_DEGREE = 7;\r
+\r
+ srand(time(0));\r
+\r
+ for (int i = 1; i <= MATRIX_COUNT; ++i)\r
+ {\r
+ size_t src_size = (int)(std::pow(2.0, (rand()%MAX_DEGREE+1)*1.0));\r
\r
- srand(time(0));\r
+ cv::Mat src(src_size, src_size, type);\r
\r
- for (size_t i = 1; i <= MATRIX_COUNT; ++i)\r
- {\r
- size_t src_size = (int)(std::pow(2.0, (rand()%MAX_DEGREE+1)*1.0)); \r
- \r
- cv::Mat src(src_size, src_size, type);\r
+ for (int j = 0; j < src.rows; ++j)\r
+ for (int k = j; k < src.cols; ++k)\r
+ if (type == CV_32FC1) src.at<float>(k, j) = src.at<float>(j, k) = cv::randu<float>();\r
+ else src.at<double>(k, j) = src.at<double>(j, k) = cv::randu<double>();\r
\r
- for (int j = 0; j < src.rows; ++j)\r
- for (int k = j; k < src.cols; ++k) \r
- if (type == CV_32FC1) src.at<float>(k, j) = src.at<float>(j, k) = cv::randu<float>();\r
- else src.at<double>(k, j) = src.at<double>(j, k) = cv::randu<double>();\r
- \r
- if (!test_values(src)) return false;\r
+ if (!test_values(src)) return false;\r
\r
- src.~Mat();\r
- }\r
+ src.~Mat();\r
+ }\r
\r
- return true;\r
+ return true;\r
}\r
\r
-// TEST(Core_Eigen_Scalar_32, single_complex) {Core_EigenTest_Scalar_32 test; test.safe_run(); }\r
-// TEST(Core_Eigen_Scalar_64, single_complex) {Core_EigenTest_Scalar_64 test; test.safe_run(); }\r
-TEST(Core_Eigen_32, complex) { Core_EigenTest_32 test; test.safe_run(); }\r
-TEST(Core_Eigen_64, complex) { Core_EigenTest_64 test; test.safe_run(); }
\ No newline at end of file
+// TEST(Core_Eigen_Scalar_32, accuracy) {Core_EigenTest_Scalar_32 test; test.safe_run(); }\r
+// TEST(Core_Eigen_Scalar_64, accuracy) {Core_EigenTest_Scalar_64 test; test.safe_run(); }\r
+TEST(Core_Eigen_32, accuracy) { Core_EigenTest_32 test; test.safe_run(); }\r
+TEST(Core_Eigen_64, accuracy) { Core_EigenTest_64 test; test.safe_run(); }\r