I want to write a short function to display OpenCV Mat matrix type. I'm closed to finish it. This is my code:
template <class eleType>
int MATmtxdisp(const Mat mtx, eleType fk)
// create function template to avoid type dependent programming i.e. Mat element can be float, Vec2f, Vec3f, Vec4f
// cannot get rid of fk ('fake') variable to identify Mat element type
{
uchar chan = mtx.channels();
for(int i = 0; i < mtx.rows; i++)
for(int k = 0; k < chan; k++)
{
for(int l = 0; l < mtx.cols; l++)
{
eleType ele = mtx.at<eleType>(i,l);
// I even split 2 cases for 1 channel and multi-channel element
// but this is unacceptable by the compiler when element is float type (1 channel)
// i.e. C2109: subscript requires array or pointer type
if (chan > 1)
printf("%8.2f",ele[k]);
else
printf("%8.2f",ele);
}
printf("\n");
}
return 0;
}
is there any way that I can get around this to have a compact and channel num free display function???