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. 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?