Reputation: 1219
I am writing a function that takes a OpenCV Mat structure and does some processing. The problem is that OpenCV doesn't seem to have a type independent way for accessing the strucutre so I have to do something like this.
int myfunc(cv::Mat& im, int iRow, int iCol)
{
int iResult = 0;
if (im.type()==CV_16U) iResult = (int)im.at<unsighed short>(iRow, icol);
else if (im.type()==CV_8U) iResult = (int)im.at<uchar>(iRow, icol);
return iResult;
}
Is there a clean way to do this?
Upvotes: 3
Views: 817
Reputation: 96109
It's because you generally require high performance in image processing and so need different algorithms for 8bit, 16bit or double image types.
You can do it all with templated types but that's often just a less readable way of having a switch statement.
ps if you do care about performance you shouldn't be using the .at<> operator, get a pointer to the start of the line with .ptr() and then step in units of whatever pixel type you have
Upvotes: 1