c++ - How to generate a cv::Mat type code? -


i've been using c-style api generate opencv type codes. example:

cv::mat(h, w, cv_8uc2); 

cv_8uc2 macro defined in types_c.h (deprecated?):

#define cv_maketype(depth,cn) (cv_mat_depth(depth) + (((cn)-1) << cv_cn_shift)) 

is there similar type code generation function in c++ api,

mat m(w,h, cv::type(vec<unsigned char, 2>).typecode()) ? 

as said in comments, cv_maketype not deprecated, , afaik standard way of generating "type codes".

however (and fun), alternative, more c++-ish, way of generating arbitrary codes (still in compile time) can achieved using tmp...

template <int depth,           int cn> struct make_type {     enum {        // (yes, same expression used cv_maketype)        value = ((depth) & cv_mat_depth_mask) + (((cn)-1) << cv_cn_shift)     }; };  // can check works same good, old `cv_maketype`      cout << make_type<cv_8u,2>::value << " "<< cv_maketype(cv_8u,2) << endl; 

... don't this. while tmp fun , amazing, cv_maketype right way of doing things in case.

edit: opencv has own type traits utilities. in core/traits.hpp can find class datatype:

the datatype class used provide description of ... primitive data types without adding fields or methods corresponding classes (and impossible add primitive c/c++ data types). technique known in c++ class traits. not datatype used specialized versions ... main purpose of class convert compilation-time type information opencv-compatible data type identifier ...

so, such traits used tell opencv data type working with, if such type not native opencv.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -