Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

No. In general case Mat's type is unknown in compilation time.

You can use template class Mat_:

template <typename T> void func(Mat_<T> img);

cv::Mat_<float> mat;
mat.create(rows, cols);

or use switch/if construction:

switch (mat.type())
case CV_8UC1:
        uchar* ptr = mat.ptr<uchar>();

case CV_8UC3:
        Vec3b* ptr = mat.ptr<Vec3b>();

or use table of pointer to functions

typedef void (*func_ptr_t)(Mat img);
func_ptr_t funcs[7][4] = 
    {&func_8u_c1, &func_8u_c2, ...},
    {&func_32f_c1, &func_32f_c2, ...}
funcs[img.depth()][img.channels() - 1](img);