OpenCV + Astropy + FITS Unrecognized or Unsupported Array Type
I'm trying to read a FITS image file and display it using imshow. I can read in an image and I've checked that it isn't empty and has the expected dimensions. I also checked the image type which is '>i2' AKA big endian signed 16-bit integer. I've tried converting it into a 32-bit float image, an 8-bit unsigned int image, and 16-bit unsigned int image. Every time though I get the same error:
cv2.error: OpenCV(3.4.3) /io/opencv/modules/core/src/array.cpp:2492: error: (-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type in function 'cvGetMat'
when I call the imshow
function. I've also tried to use pyplot to display the image as shown here. Then I got a new error:
TypeError: Invalid dimensions for image data
Below is the code I'm using.
import cv2
from astropy import fits
with fits.open(fn) as hdul:
print(f'length: {len(hdul)}')
img = hdul[0].data
cv2.imshow('Viewer', img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
I've upload an example image to my Google Drive in case anyone wants to try the code.
How can I display this image using imshow?
you need to make a numpy array from it
is (1 hour ago) just for me ? anyone reported it recently :)
@sturkmen, the clock is off by 1 for anyone here ;) (and it also was always like this)
@berak the img variable is a numpy array
try cv2.imshow('Viewer', img[0,:,:])