EstervQrCode 2.0.0
Library for qr code manipulation
Loading...
Searching...
No Matches
cv::DataType< _Tp > Class Template Reference

Template "trait" class for OpenCV primitive data types. More...

#include <traits.hpp>

Detailed Description

template<typename _Tp>
class cv::DataType< _Tp >

Template "trait" class for OpenCV primitive data types.

Note
Deprecated. This is replaced by "single purpose" traits: traits::Type and traits::Depth

A primitive OpenCV data type is one of unsigned char, bool, signed char, unsigned short, signed short, int, float, double, or a tuple of values of one of these types, where all the values in the tuple have the same type. Any primitive type from the list can be defined by an identifier in the form CV_<bit-depth>{U|S|F}C(<number_of_channels>), for example: uchar CV_8UC1, 3-element floating-point tuple CV_32FC3, and so on. A universal OpenCV structure that is able to store a single instance of such a primitive data type is Vec. Multiple instances of such a type can be stored in a std::vector, Mat, Mat_, SparseMat, SparseMat_, or any other container that is able to store Vec instances.

The DataType class is basically used to provide a description of such primitive data types without adding any fields or methods to the corresponding classes (and it is actually impossible to add anything to primitive C/C++ data types). This technique is known in C++ as class traits. It is not DataType itself that is used but its specialized versions, such as:

template<> class DataType<uchar>
{
typedef uchar value_type;
typedef int work_type;
typedef uchar channel_type;
enum { channel_type = CV_8U, channels = 1, fmt='u', type = CV_8U };
};
...
template<typename _Tp> DataType<std::complex<_Tp> >
{
typedef std::complex<_Tp> value_type;
typedef std::complex<_Tp> work_type;
typedef _Tp channel_type;
// DataDepth is another helper trait class
};
...
@ value
Definition traits.hpp:289
@ fmt
Definition traits.hpp:290
Template "trait" class for OpenCV primitive data types.
Definition traits.hpp:113
int int channels
Definition core_c.h:100
int int type
Definition core_c.h:221
int depth
Definition core_c.h:100
#define CV_8U
Definition interface.h:73
unsigned char uchar
Definition interface.h:51
#define CV_MAKETYPE(depth, cn)
Definition interface.h:85

The main purpose of this class is to convert compilation-time type information to an OpenCV-compatible data type identifier, for example:

// allocates a 30x40 floating-point matrix
// the statement below will print 6, 2 , that is depth == CV_64F, channels == 2
cout << B.depth() << ", " << B.channels() << endl;
Template matrix class derived from Mat.
Definition mat.hpp:2230
int depth() const
n-dimensional dense array class
Definition mat.hpp:812
const CvArr const CvArr const CvArr * B
Definition core_c.h:1341

So, such traits are used to tell OpenCV which data type you are working with, even if such a type is not native to OpenCV. For example, the matrix B initialization above is compiled because OpenCV defines the proper specialized template class DataType<complex<_Tp> > . This mechanism is also useful (and used in OpenCV this way) for generic algorithms implementations.

Note
Default values were dropped to stop confusing developers about using of unsupported types (see #7599)

The documentation for this class was generated from the following file: