From 7ee604019269f543598e72aaf71571bab1ddb264 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Thu, 11 Oct 2012 15:02:48 +0400 Subject: [PATCH] enable Matx as Mat elements (bug #1705). --- modules/core/include/opencv2/core/core.hpp | 12 +++++++++++ modules/core/test/test_operations.cpp | 24 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 9ffe7d4bbb..2c1ff04421 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -1107,6 +1107,18 @@ public: type = CV_MAKETYPE(depth, channels) }; }; +template class DataType > +{ +public: + typedef Matx<_Tp, m, n> value_type; + typedef Matx::work_type, m, n> work_type; + typedef _Tp channel_type; + typedef value_type vec_type; + enum { generic_type = 0, depth = DataDepth::value, channels = m*n, + fmt = ((channels-1)<<8) + DataDepth::fmt, + type = CV_MAKETYPE(depth, channels) }; +}; + template class DataType > { public: diff --git a/modules/core/test/test_operations.cpp b/modules/core/test/test_operations.cpp index ebdaaef81a..5e3964d823 100644 --- a/modules/core/test/test_operations.cpp +++ b/modules/core/test/test_operations.cpp @@ -69,6 +69,7 @@ protected: bool SomeMatFunctions(); bool TestMat(); + template void TestType(Size sz, _Tp value=_Tp(1.f)); bool TestTemplateMat(); bool TestMatND(); bool TestSparseMat(); @@ -106,6 +107,19 @@ CV_OperationsTest::~CV_OperationsTest() {} #define MSVC_OLD 0 #endif +template void CV_OperationsTest::TestType(Size sz, _Tp value) +{ + cv::Mat_<_Tp> m(sz); + CV_Assert(m.cols == sz.width && m.rows == sz.height && m.depth() == DataType<_Tp>::depth && + m.channels() == DataType<_Tp>::channels && + m.elemSize() == sizeof(_Tp) && m.step == m.elemSize()*m.cols); + for( int y = 0; y < sz.height; y++ ) + for( int x = 0; x < sz.width; x++ ) + m(y, x) = value; + + CV_Assert( sum(m.reshape(1,1))[0] == (double)sz.width*sz.height ); +} + bool CV_OperationsTest::TestMat() { try @@ -779,6 +793,16 @@ bool CV_OperationsTest::TestTemplateMat() badarg_catched = true; } CV_Assert( badarg_catched ); + +#include +#include + + Size size(2, 5); + TestType(size); + TestType(size); + TestType(size); + TestType(size); + TestType(size); } catch (const test_excep& e) { -- GitLab