2

I have some algorithm in OpenCV and I want to rewrite it using fixed point value representation. I found class for fixed point arithmetic here: https://github.com/eteran/cpp-utilities. I'd like to know if there's some elegant way to use Mat_ template class with Fixed class objects (or any custom class) as contents of Mat. When I use:

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

I'm getting following errors:

Error   C2039   'value' : is not a member of 'cv::DataDepth<numeric::Fixed<0x0c,0x04>>' opencv_hog  D:\libs\x64\opencv_2_4_13\build\include\opencv2\core\core.hpp   1134
Error   C2065   'value' : undeclared identifier opencv_hog  D:\libs\x64\opencv_2_4_13\build\include\opencv2\core\core.hpp   1134
Error   C2039   'fmt' : is not a member of 'cv::DataDepth<numeric::Fixed<0x0c,0x04>>'   opencv_hog  D:\libs\x64\opencv_2_4_13\build\include\opencv2\core\core.hpp   1135    
Error   C2065   'fmt' : undeclared identifier   opencv_hog  D:\libs\x64\opencv_2_4_13\build\include\opencv2\core\core.hpp   1135    
Error   C2056   illegal expression  opencv_hog  D:\libs\x64\opencv_2_4_13\build\include\opencv2\core\core.hpp   1135
BartekM
  • 106
  • 3
  • 8
  • 2
    You may want to look at this documentation: http://www.docs.opencv.org/ref/master/d0/d3a/classcv_1_1DataType.html#gsc.tab=0 I think you should define a template specialization for using it. – jnbrq -Canberk Sönmez Jul 06 '16 at 23:12
  • Thanks for suggestion! I've made an attempt to do what you said, results below, in answer to my question. – BartekM Jul 08 '16 at 15:39

1 Answers1

0

As it was mentioned in comments, I needed to define template specialization:

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)
    };
};

So far, it seems to work fine. For example, I can write:

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;

And this will output:

0.0
2.375
BartekM
  • 106
  • 3
  • 8