I have the following piece of code, which I created for changing the intensity of a pixel in an OpenCV image (Cv::Mat class).
As you can see, I’m looping in both cases, but with different template type.
The ‘transfer’ function can be overloaded.
My question is, therefore, how can I create dynamic template type so that it looks better ..
Mat mat = _mat.clone() ;
int channels = mat.channels();
switch(channels)
{
case 1:
for (int i=0; i<mat.rows; i++)
{
for (int j=0; j<mat.cols; j++)
{
uchar src = mat.at<uchar>(i,j);
uchar dst = mat.at<uchar>(i,j);
t.transfer(src, dst);
}
}
break;
case 3:
for (int i=0; i<mat.rows; i++)
{
for (int j=0; j<mat.cols; j++)
{
Vec3b src = mat.at<Vec3b>(i,j);
Vec3b dst = mat.at<Vec3b>(i,j);
t.transfer(src, dst);
}
}
break;
}
return mat ;
How about something like this:
Then you can say: