I need to access a cv::Mat
, but i don't have to know the sizeof
the Matrix, so is there a way to access the elements of a cv::Mat
for all the sizes? I mean without doing a switch on the type of the Matrix.
So this is what i have :
int image_type = image.type();
switch (image_type)
{
case CV_32F :
return image.at<float>(i,j);
case CV_8U :
return (float)image.at<uchar>(i,j);
.
.
.
default:
std::string msg = "Exception : cannot access IMAGE of type : " + image_type;
throw std::exception(msg.c_str());
break;
}
what I'm doing is accessing the data of the matrix and then transform it to floats (since i work with matrix with 32F max), this code is working fine but I'm looking for something like this : float x = image.at(i,j); but that would work for a matrix 8U and others ...
Thanks !