I'm not sure where to find this information.
I loaded in a .jpg and converted it to grayscale with cv::cvtColor(*input_image_grayscale, *input_image_grayscale, CV_BGR2GRAY);
I then try to reference a pixel with input_image_grayscale->at<float>(row, col)
but get an assertion error. How do I determine the right type of data (it's clearly not float) to dereference this? Thanks
For reference, I ran input_image_grayscale->type()
and got 0.
The value returned by type is just an integer that OpenCV declares with a preprocessor define. You can check it in a switch statement like this:
switch( matrixType )
{
case CV_8UC1:
.... check for other types
}
The 8U
, in that example refers to an unsigned char, and C1
refers to a single channel image. CV_8UC1 is defined as 0
, so that is your Mat's type and you should use unsigned char
for your reference type.
You can also use the function Mat::depth, to return the type of the size of a single matrix element, because you already know it is a single channel image since it is grayscale.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With