-1

I have a numpy array with shape (617, 767), dtype = int32. Max value in the array is 164, min value in the array is -166. When I use cv2.imshow to show this array like an image I get this error:

error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'

I understand that cv2.imshow converts negative values to 0 before showing an array like an image. Then why I'm getting this error? Thanks in advance

Dan Mašek
  • 17,852
  • 6
  • 57
  • 85
DLopezG
  • 115
  • 1
  • 5

1 Answers1

0

As stated here, you can use PIL library.

  • Convert your array to image using fromarray function.

For instance:

import cv2
from PIL import Image

# data is your numpy array with shape (617, 767)
img = Image.fromarray(data, 'RGB')

# Display with opencv
cv2.imshow("output", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Ahmet
  • 7,527
  • 3
  • 23
  • 47