I have a code in which the matrix hip_dir represents a RGB image. If I check its shape, python returns (1080, 1920, 3). If I write
cv2.imwrite('hip_dir.jpg',hip_dir)
I get the correct image saved in the folder. However, when I do
cv2.imshow('img0',hip_dir)
cv2.waitKey(0)
cv2.destroyAllWindows()
I get the same image, in black and white (there are some blue pixels, however, making this even stranger).
How can I use imshow correctly?
Edit:
Using the command cv2.cvtColor results in the following error:
error: OpenCV(4.1.0) c:\projects\opencv-
python\opencv\modules\imgproc\src\color.simd_helpers.hpp:94: error:
(-2:Unspecified error) in function '__cdecl cv::impl::`anonymous-namespace'::CvtHelper<struct cv::impl::`anonymous namespace'::Set<3,4,-1>,struct cv::impl::A0xe227985e::Set<3,4,-1>,struct cv::impl::A0xe227985e::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)'
Unsupported depth of input image:
'VDepth::contains(depth)'
where
'depth' is 6 (CV_64F)
Edit2: I discovered that the reason for this error to occur is simple because the matrix is in np.float64
. Having it converted to np.float32
, however, does not change the imshow
result.