OpenCV imshow fails with src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'

Viewed 88

Code for operating my camera is giving me images as signed 32-bit integers, and I would like to turn this into an openCV Mat.

When I have 16-bit signed integers, I do the following:

int16_t x[100][100];
Mat A(100, 100, CV_16SC1, x);
imshow("BLAH", A);

This works. Similarly, when I have 8-bit unsigned integers I use uint8_t and CV_8UC1 and it works. I can also use double and CV_64FC1 and it works. Sadly, the following does not work:

int32_t x[100][100];
Mat A(100, 100, CV_32SC1, x);
imshow("BLAH", A);

OpenCV throws a -215:Assertion failed exception on the imshow line, indicating the Mat was not properly loaded in the first place (I think). I have also tried using int instead of int32_t, but to no avail.

1 Answers

I added your error message for you. It says:

/opencv/modules/highgui/src/precomp.hpp:155: error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'

That means imshow does not accept 32 bit signed integers (nor does it accept half floats).

You need to give it anything but that. Convert your data to one of the supported types, which are currently: uint8, uint16, float, double.

Mind the value range. For the accepted integers, it's the entire range. For floats, it's 0.0 to 1.0, that are mapped to black/white. If your values don't use the expected range, you might see an entirely black image (underexposed) or one that is mostly white (overexposed).

Related