有没有办法将OpenCV Mat_与自定义类一起使用



我在OpenCV中有一些算法,我想使用定点值表示来重写它。我在这里找到了定点算术的类:https://github.com/eteran/cpp-utilities。我想知道是否有一些优雅的方法可以将模板类与固定类对象(或任何自定义类)一起使用Mat_ Mat 的内容。当我使用:

cv::Mat_<cv::Vec<Fixed<12, 4>, 3>> num;

我收到以下错误:

Error   C2039   'value' : is not a member of 'cv::DataDepth<numeric::Fixed<0x0c,0x04>>' opencv_hog  D:libsx64opencv_2_4_13buildincludeopencv2corecore.hpp   1134
Error   C2065   'value' : undeclared identifier opencv_hog  D:libsx64opencv_2_4_13buildincludeopencv2corecore.hpp   1134
Error   C2039   'fmt' : is not a member of 'cv::DataDepth<numeric::Fixed<0x0c,0x04>>'   opencv_hog  D:libsx64opencv_2_4_13buildincludeopencv2corecore.hpp   1135    
Error   C2065   'fmt' : undeclared identifier   opencv_hog  D:libsx64opencv_2_4_13buildincludeopencv2corecore.hpp   1135    
Error   C2056   illegal expression  opencv_hog  D:libsx64opencv_2_4_13buildincludeopencv2corecore.hpp   1135

正如评论中提到的,我需要定义模板专用化:

template<size_t I, size_t F> class cv::DataType<Fixed<I, F>>
{
public:
    typedef Fixed<I, F> value_type;
    typedef Fixed<I, F> work_type;
    typedef Fixed<I, F> channel_type;
    enum {
        channels = 1,
        depth = I + F,
        type = CV_MAKETYPE(depth, channels)
    };
};

到目前为止,它似乎工作正常。例如,我可以写:

cv::Mat_<Fixed<13, 3>> fixed = cv::Mat_<Fixed<13, 3>>::zeros(10, 10);
fixed(1, 1) = 2.4;
std::cout << fixed(0, 0) << std::endl;
std::cout << fixed(1, 1) << std::endl;

这将输出:

0.0
2.375

相关内容

  • 没有找到相关文章

最新更新