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

Time:07-01

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.

CodePudding user response:

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. 32 bit unsigned ints are okay. But mind the value range. imshow expects you to use the entire value range. If you don't, you see black.

  • Related