From 77b8ed586130317708a0ed0361185ee65a9163a4 Mon Sep 17 00:00:00 2001 From: Matt Leotta Date: Tue, 21 Jan 2014 13:23:50 -0500 Subject: [PATCH] fix a failing test on descriptor_set conversions Previously this test was using matrices with uninitialized values to test the conversion of ocv descriptors. The uninitialized values were treated as random or arbitrary. Unfortunately, on some platforms, some of these uninitialized value where "nan". Since (nan == nan) is false, the test indicated that conversion was failing. This fix initializes the input data to random value generated with cv::randu(), so there should be no nan or infinite values. --- tests/ocv/test_descriptor_set.cxx | 51 ++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/tests/ocv/test_descriptor_set.cxx b/tests/ocv/test_descriptor_set.cxx index 59b033384..758fb1273 100644 --- a/tests/ocv/test_descriptor_set.cxx +++ b/tests/ocv/test_descriptor_set.cxx @@ -133,34 +133,55 @@ void test_conversions(const cv::Mat& data) } } +inline cv::Mat rand_double_mat(int r, int c) +{ + cv::Mat m(r, c, CV_64F); + cv::randu(m, 0.0, 1.0); + return m; +} + +inline cv::Mat rand_float_mat(int r, int c) +{ + cv::Mat m(r, c, CV_32F); + cv::randu(m, 0.0f, 1.0f); + return m; +} + +inline cv::Mat rand_byte_mat(int r, int c) +{ + cv::Mat m(r, c, CV_8U); + cv::randu(m, 0, 255); + return m; +} + } IMPLEMENT_TEST(double_conversions) { - test_conversions(cv::Mat(1, 50, CV_64F)); - test_conversions(cv::Mat(64, 50, CV_64F)); - test_conversions(cv::Mat(128, 1, CV_64F)); - test_conversions(cv::Mat(125, 20, CV_64F)); - test_conversions(cv::Mat(256, 10, CV_64F)); + test_conversions(rand_double_mat(1, 50)); + test_conversions(rand_double_mat(64, 50)); + test_conversions(rand_double_mat(128, 1)); + test_conversions(rand_double_mat(125, 20)); + test_conversions(rand_double_mat(256, 10)); } IMPLEMENT_TEST(float_conversions) { - test_conversions(cv::Mat(1, 50, CV_32F)); - test_conversions(cv::Mat(64, 50, CV_32F)); - test_conversions(cv::Mat(128, 1, CV_32F)); - test_conversions(cv::Mat(125, 20, CV_32F)); - test_conversions(cv::Mat(256, 10, CV_32F)); + test_conversions(rand_float_mat(1, 50)); + test_conversions(rand_float_mat(64, 50)); + test_conversions(rand_float_mat(128, 1)); + test_conversions(rand_float_mat(125, 20)); + test_conversions(rand_float_mat(256, 10)); } IMPLEMENT_TEST(byte_conversions) { - test_conversions(cv::Mat(1, 50, CV_8U)); - test_conversions(cv::Mat(64, 50, CV_8U)); - test_conversions(cv::Mat(128, 1, CV_8U)); - test_conversions(cv::Mat(125, 20, CV_8U)); - test_conversions(cv::Mat(256, 10, CV_8U)); + test_conversions(rand_byte_mat(1, 50)); + test_conversions(rand_byte_mat(64, 50)); + test_conversions(rand_byte_mat(128, 1)); + test_conversions(rand_byte_mat(125, 20)); + test_conversions(rand_byte_mat(256, 10)); }