From e18224110c44af42deff84cbaf4c7cf6c5664c58 Mon Sep 17 00:00:00 2001 From: Istvan Sarandi Date: Thu, 17 Apr 2014 02:41:52 +0200 Subject: [PATCH 1/4] Removed emptiness check from cv::hconcat and cv::vconcat. Sometimes you want to concatenate with an empty matrix. --- modules/core/src/matrix.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index f7aded7312..6458145a61 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -2665,7 +2665,7 @@ void cv::hconcat(const Mat* src, size_t nsrc, OutputArray _dst) size_t i; for( i = 0; i < nsrc; i++ ) { - CV_Assert( !src[i].empty() && src[i].dims <= 2 && + CV_Assert( src[i].dims <= 2 && src[i].rows == src[0].rows && src[i].type() == src[0].type()); totalCols += src[i].cols; @@ -2705,7 +2705,7 @@ void cv::vconcat(const Mat* src, size_t nsrc, OutputArray _dst) size_t i; for( i = 0; i < nsrc; i++ ) { - CV_Assert( !src[i].empty() && src[i].dims <= 2 && + CV_Assert(src[i].dims <= 2 && src[i].cols == src[0].cols && src[i].type() == src[0].type()); totalRows += src[i].rows; From 2421ac3958537a9bee16ce0a8a5875d146cb7f64 Mon Sep 17 00:00:00 2001 From: Istvan Sarandi Date: Thu, 24 Apr 2014 02:43:28 +0200 Subject: [PATCH 2/4] Added test for concatenation with empty matrices. --- modules/core/test/test_concatenation.cpp | 147 +++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 modules/core/test/test_concatenation.cpp diff --git a/modules/core/test/test_concatenation.cpp b/modules/core/test/test_concatenation.cpp new file mode 100644 index 0000000000..a3c6d1077f --- /dev/null +++ b/modules/core/test/test_concatenation.cpp @@ -0,0 +1,147 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "test_precomp.hpp" + +using namespace cv; +using namespace std; + +class Core_ConcatenationTest : public cvtest::BaseTest +{ +public: + Core_ConcatenationTest(bool horizontal, bool firstEmpty, bool secondEmpty); +protected: + int prepare_test_case( int ); + void run_func(); + int validate_test_results( int ); + + Mat mat0x5; + Mat mat10x5; + Mat mat20x5; + + Mat mat5x0; + Mat mat5x10; + Mat mat5x20; + + Mat result; + + bool horizontal; + bool firstEmpty; + bool secondEmpty; + +private: + static bool areEqual(const Mat& m1, const Mat& m2); + +}; + +Core_ConcatenationTest::Core_ConcatenationTest(bool horizontal, bool firstEmpty, bool secondEmpty) + : horizontal(horizontal) + , firstEmpty(firstEmpty) + , secondEmpty(secondEmpty) +{ + test_case_count = 1; + + mat0x5 = Mat::ones(0,5, CV_8U); + mat10x5 = Mat::ones(10,5, CV_8U); + mat20x5 = Mat::ones(20,5, CV_8U); + + mat5x0 = Mat::ones(5,0, CV_8U); + mat5x10 = Mat::ones(5,10, CV_8U); + mat5x20 = Mat::ones(5,20, CV_8U); +} + +int Core_ConcatenationTest::prepare_test_case( int test_case_idx ) +{ + cvtest::BaseTest::prepare_test_case( test_case_idx ); + return 1; +} + +void Core_ConcatenationTest::run_func() +{ + if (horizontal) + { + cv::hconcat((firstEmpty ? mat5x0 : mat5x10), + (secondEmpty ? mat5x0 : mat5x10), + result); + } else { + cv::vconcat((firstEmpty ? mat0x5 : mat10x5), + (secondEmpty ? mat0x5 : mat10x5), + result); + } +} + +int Core_ConcatenationTest::validate_test_results( int ) +{ + Mat expected; + + if (firstEmpty && secondEmpty) + expected = (horizontal ? mat5x0 : mat0x5); + else if ((firstEmpty && !secondEmpty) || (!firstEmpty && secondEmpty)) + expected = (horizontal ? mat5x10 : mat10x5); + else + expected = (horizontal ? mat5x10 : mat10x5); + + if (areEqual(expected, result)) + { + return cvtest::TS::OK; + } else + { + ts->printf( cvtest::TS::LOG, "Concatenation failed"); + ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); + } + + return cvtest::TS::OK; +} + +bool Core_ConcatenationTest::areEqual(const Mat &m1, const Mat &m2) +{ + return m1.size() == m2.size() + && m1.type() == m2.type() + && countNonZero(m1 != m2) == 0; +} + +TEST(Core_Concatenation, hconcat_empty_nonempty) { Core_ConcatenationTest test(true, true, false); test.safe_run(); } +TEST(Core_Concatenation, hconcat_nonempty_empty) { Core_ConcatenationTest test(true, false, true); test.safe_run(); } +TEST(Core_Concatenation, hconcat_empty_empty) { Core_ConcatenationTest test(true, true, true); test.safe_run(); } + +TEST(Core_Concatenation, vconcat_empty_nonempty) { Core_ConcatenationTest test(false, true, false); test.safe_run(); } +TEST(Core_Concatenation, vconcat_nonempty_empty) { Core_ConcatenationTest test(false, false, true); test.safe_run(); } +TEST(Core_Concatenation, vconcat_empty_empty) { Core_ConcatenationTest test(false, true, true); test.safe_run(); } From c20cab9ec1492253c758032ff23d24ed7dcabeb3 Mon Sep 17 00:00:00 2001 From: Istvan Sarandi Date: Thu, 24 Apr 2014 02:43:28 +0200 Subject: [PATCH 3/4] Added test for concatenation with empty matrices. --- modules/core/test/test_concatenation.cpp | 147 +++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 modules/core/test/test_concatenation.cpp diff --git a/modules/core/test/test_concatenation.cpp b/modules/core/test/test_concatenation.cpp new file mode 100644 index 0000000000..b6b34cbf37 --- /dev/null +++ b/modules/core/test/test_concatenation.cpp @@ -0,0 +1,147 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "test_precomp.hpp" + +using namespace cv; +using namespace std; + +class Core_ConcatenationTest : public cvtest::BaseTest +{ +public: + Core_ConcatenationTest(bool horizontal, bool firstEmpty, bool secondEmpty); +protected: + int prepare_test_case( int ); + void run_func(); + int validate_test_results( int ); + + Mat mat0x5; + Mat mat10x5; + Mat mat20x5; + + Mat mat5x0; + Mat mat5x10; + Mat mat5x20; + + Mat result; + + bool horizontal; + bool firstEmpty; + bool secondEmpty; + +private: + static bool areEqual(const Mat& m1, const Mat& m2); + +}; + +Core_ConcatenationTest::Core_ConcatenationTest(bool horizontal, bool firstEmpty, bool secondEmpty) + : horizontal(horizontal) + , firstEmpty(firstEmpty) + , secondEmpty(secondEmpty) +{ + test_case_count = 1; + + mat0x5 = Mat::ones(0,5, CV_8U); + mat10x5 = Mat::ones(10,5, CV_8U); + mat20x5 = Mat::ones(20,5, CV_8U); + + mat5x0 = Mat::ones(5,0, CV_8U); + mat5x10 = Mat::ones(5,10, CV_8U); + mat5x20 = Mat::ones(5,20, CV_8U); +} + +int Core_ConcatenationTest::prepare_test_case( int test_case_idx ) +{ + cvtest::BaseTest::prepare_test_case( test_case_idx ); + return 1; +} + +void Core_ConcatenationTest::run_func() +{ + if (horizontal) + { + cv::hconcat((firstEmpty ? mat5x0 : mat5x10), + (secondEmpty ? mat5x0 : mat5x10), + result); + } else { + cv::vconcat((firstEmpty ? mat0x5 : mat10x5), + (secondEmpty ? mat0x5 : mat10x5), + result); + } +} + +int Core_ConcatenationTest::validate_test_results( int ) +{ + Mat expected; + + if (firstEmpty && secondEmpty) + expected = (horizontal ? mat5x0 : mat0x5); + else if ((firstEmpty && !secondEmpty) || (!firstEmpty && secondEmpty)) + expected = (horizontal ? mat5x10 : mat10x5); + else + expected = (horizontal ? mat5x20 : mat20x5); + + if (areEqual(expected, result)) + { + return cvtest::TS::OK; + } else + { + ts->printf( cvtest::TS::LOG, "Concatenation failed"); + ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); + } + + return cvtest::TS::OK; +} + +bool Core_ConcatenationTest::areEqual(const Mat &m1, const Mat &m2) +{ + return m1.size() == m2.size() + && m1.type() == m2.type() + && countNonZero(m1 != m2) == 0; +} + +TEST(Core_Concatenation, hconcat_empty_nonempty) { Core_ConcatenationTest test(true, true, false); test.safe_run(); } +TEST(Core_Concatenation, hconcat_nonempty_empty) { Core_ConcatenationTest test(true, false, true); test.safe_run(); } +TEST(Core_Concatenation, hconcat_empty_empty) { Core_ConcatenationTest test(true, true, true); test.safe_run(); } + +TEST(Core_Concatenation, vconcat_empty_nonempty) { Core_ConcatenationTest test(false, true, false); test.safe_run(); } +TEST(Core_Concatenation, vconcat_nonempty_empty) { Core_ConcatenationTest test(false, false, true); test.safe_run(); } +TEST(Core_Concatenation, vconcat_empty_empty) { Core_ConcatenationTest test(false, true, true); test.safe_run(); } From 4bf1df7da303ba105f047d0ac936ce8894998a9d Mon Sep 17 00:00:00 2001 From: Istvan Sarandi Date: Sat, 26 Apr 2014 00:42:26 +0200 Subject: [PATCH 4/4] Suppress warning in constructor. --- modules/core/test/test_concatenation.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/core/test/test_concatenation.cpp b/modules/core/test/test_concatenation.cpp index b6b34cbf37..e2246f0e58 100644 --- a/modules/core/test/test_concatenation.cpp +++ b/modules/core/test/test_concatenation.cpp @@ -72,10 +72,10 @@ private: }; -Core_ConcatenationTest::Core_ConcatenationTest(bool horizontal, bool firstEmpty, bool secondEmpty) - : horizontal(horizontal) - , firstEmpty(firstEmpty) - , secondEmpty(secondEmpty) +Core_ConcatenationTest::Core_ConcatenationTest(bool horizontal_, bool firstEmpty_, bool secondEmpty_) + : horizontal(horizontal_) + , firstEmpty(firstEmpty_) + , secondEmpty(secondEmpty_) { test_case_count = 1;