Ken Y-N
Ken Y-N

Reputation: 15018

cv::DataType<> versus cv::traits::Type<>

As far as I can determine (I cannot find decent documentation, however), in OpenCV 3.3 the cv::DataType was replaced by cv::traits::Type<>, so to get to compile on both versions I need to do something like this:

template <typename T>
void f(cv::Mat &src)
{
    using DstPixel = cv::Vec<T, 3>;

    dst.create(src.rows,
               src.cols,
#if CV_VERSION_MAJOR >= 3 && CV_VERSION_MINOR >= 3
               cv::traits::Type<DstPixel>::value);
#else
               cv::DataType<DstPixel>::type);
#endif
}

This looks a little messy, and it seems a bit odd there isn't a backward-compatibility path for a minor version change. Is there a cleaner way of getting code to compile with either version?

(Note that this answer also needs updating to cv::traits::Type<>)

Upvotes: 3

Views: 1266

Answers (1)

fortuna
fortuna

Reputation: 316

One possible solution is to define somewhere in your project OPENCV_TRAITS_ENABLE_DEPRECATED with #define OPENCV_TRAITS_ENABLE_DEPRECATED or as a compile option -DOPENCV_TRAITS_ENABLE_DEPRECATED.

If it is defined you can continue to use in your code the old DataType structure:

cv::DataType<DstPixel>::type

However the new traits system has been introduced to solve some issue related to DataType. See https://github.com/opencv/opencv/issues/10115

Upvotes: 3

Related Questions