提交 7ee60401 编写于 作者: V Vadim Pisarevsky

enable Matx as Mat elements (bug #1705).

上级 e435674a
......@@ -1107,6 +1107,18 @@ public:
type = CV_MAKETYPE(depth, channels) };
};
template<typename _Tp, int m, int n> class DataType<Matx<_Tp, m, n> >
{
public:
typedef Matx<_Tp, m, n> value_type;
typedef Matx<typename DataType<_Tp>::work_type, m, n> work_type;
typedef _Tp channel_type;
typedef value_type vec_type;
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = m*n,
fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
type = CV_MAKETYPE(depth, channels) };
};
template<typename _Tp, int cn> class DataType<Vec<_Tp, cn> >
{
public:
......
......@@ -69,6 +69,7 @@ protected:
bool SomeMatFunctions();
bool TestMat();
template<typename _Tp> 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<typename _Tp> 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 <iostream>
#include <opencv2/core/core.hpp>
Size size(2, 5);
TestType<float>(size);
TestType<cv::Vec3f>(size);
TestType<cv::Matx31f>(size);
TestType<cv::Matx41f>(size);
TestType<cv::Matx32f>(size);
}
catch (const test_excep& e)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册