C++ – Accessing elements of OpenCV Mat CV_16UC1

copencv

i tried with the following line code:

image.at<char>(row, column);
image.at<uchar>(row, column);
image.at<unsigned char>(row, column);
image.at<double>(row, column);

what is wrong?

after that, i need to convert this value to a float. A casting is enough?

Best Answer

CV_16UC1 has unsigned short as an underlying type, so you probably need

unsigned short val = image.at<unsigned short>(row, column);

And yes, you can simply static cast that to a float afterwards:

float fval = static_cast<float>(val);