学习OpenCV3: DataType「Complexf」无法访问成员type和depth

1、背景

#include 
using namespace std;
#include 
using namespace cv;

int main()
{
    int rows = 5, cols = 5;
    Mat m = Mat::eye(rows, cols, DataType::type);
    for (size_t i = 0; i < rows; ++i)
    {
        for (size_t j = 0; j < cols; ++j)
        {
            cout << m.at(i, j).re << "," << m.at(i, j).im << "  ";
        }
        cout << endl;
    }
    cout << endl
         << DataType::depth << endl;
    return 0;
}

p70.cpp: In function ‘int main()’:
p70.cpp:9:54: error: ‘type’ is not a member of ‘cv::DataType
Mat m = Mat::eye(rows, cols, DataType::type);
p70.cpp:18:33: error: ‘depth’ is not a member of ‘cv::DataType
cout << DataType::depth << endl;

2、解决方法

  打开DataType的定义可发现,DataType< Complex<_Tp> >确实含有成员type和depth,但其要求OPENCV_TRAITS_ENABLE_DEPRECATED已定义。

template class DataType< Complex<_Tp> >
{
public:
    typedef Complex<_Tp> value_type;
    typedef value_type   work_type;
    typedef _Tp          channel_type;

    enum { generic_type = 0,
           channels     = 2,
           fmt          = DataType::fmt + ((channels - 1) << 8)
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
           ,depth        = DataType::depth
           ,type         = CV_MAKETYPE(depth, channels)
#endif
    };

    typedef Vec vec_type;
};

方法1:
  故可在打开include/opencv2/core/traist.hpp文件,将// #define OPENCV_TRAITS_ENABLE_DEPRECATED改为#define OPENCV_TRAITS_ENABLE_DEPRECATED

学习OpenCV3: DataType「Complexf」无法访问成员type和depth_第1张图片

学习OpenCV3: DataType「Complexf」无法访问成员type和depth_第2张图片

方法2:
  按depth和type的定义修改程序,即将DataType::depth修改为DataType::depth,将DataType::type修改为CV_MAKETYPE(DataType::depth, 2)

#include 
using namespace std;
#include 
using namespace cv;

int main()
{
    int rows = 5, cols = 5;
    Mat m = Mat::eye(rows, cols, CV_MAKETYPE(DataType::depth, 2));
    for (size_t i = 0; i < rows; ++i)
    {
        for (size_t j = 0; j < cols; ++j)
        {
            cout << m.at(i, j).re << "," << m.at(i, j).im << "  ";
        }
        cout << endl;
    }
    cout << endl
         << DataType::depth << endl;
    return 0;
}

学习OpenCV3: DataType「Complexf」无法访问成员type和depth_第3张图片

你可能感兴趣的:(#,学习OpenCV3)