opencv: dataType

转载于:https://blog.csdn.net/room08304/article/details/77995179






cv::DataType<_Tp>在C++中作为一个类,有两种构造方法:
struct
class
Opencv对象的容器中。

DataType自身而是其特定的版本,比如
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
enum { depth = DataDepth<_Tp>::value, channels=2,
fmt=(channels-1)*256+DataDepth<_Tp>::fmt,
type=CV_MAKETYPE(depth, channels) };
};

这里对上述代码给予一些解释:
以上是两种不同数据类型的DataType类的构造,第一个是”uchar”,第二个是”std::complex<_Tp>(复数)”,template模板中除了三个成员变量”value_type”,”work_type”,”channel_type”外,还有一个枚举结构,其中cv::DataDepth< _Tp >是用于表述被Opencv支持的基本数值的类,这个类具有两个成员变量
enum {
value = DataType<_Tp>::depth,
fmt = DataType<_Tp>::fmt
}

注:fmt表示format
回归主题,DataType<_Tp>这个类的主要功能是将compilation-time类型的数据转换为可兼容于Opencv数据类型的标识符,例如
// allocates a 30x40 floating-point matrix
Mat A(30, 40, DataType<float>::type);
Mat B = Mat_<std::complex<double> >(3, 3);
// the statement below will print 6, 2 , that is depth == CV_64F, channels == 2
cout << B.depth() << ", " << B.channels() << endl;

所以这个特性用于告诉Opencv当前用户正在使用的数据类型,即使这种类型并不是Opencv自带的。例如矩阵初始化可以被编译,就是因为Opencv定义了一个合适的特定的模板 DataType



        </article>

其实datatype就是将c++类型转换成对应的opencv数据类型。





cv::DataType<_Tp>在C++中作为一个类,有两种构造方法:
struct
class
Opencv对象的容器中。

猜你喜欢

转载自blog.csdn.net/Du_Shuang/article/details/82715227