Judita
Judita

Reputation: 13

OpenCV allowed data types

I am working with OpenCV in Python. I found that working with uint8 and float32 works in OpenCV 4. This question OpenCV Mat element types and their sizes shows some more data types but I got an error when choosing e.g. 64bit float.

If I simply create a array of integers e.g.:

img1 = np.array([[[5, 255, 20], [4, 9, 85]],
         [[6, 12, 150], [14, 8, 0]]
])

and try to convert BGR to RGB with img2 = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB) , I get an error:

 OpenCV(4.6.0) d:\a\opencv-python\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::A0xf2302844::Set<3,4,-1>,struct cv::impl::A0xf2302844::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 4 (CV_32S)

If I read a PNG image and e.g. divide it by 2 and get decimal numbers, the error I get when trying to apply the same function is:

OpenCV(4.6.0) d:\a\opencv-python\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::A0xf2302844::Set<3,4,-1>,struct cv::impl::A0xf2302844::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)

My questions are:

  1. Are the uint8 and float32 the only data types that work in OpenCV?
  2. Are the uint8 and float32 the only data types that work in OpenCV for 3-channel representation (RGB/BGR) and grayscale?
  3. If the answer is yes, why are those data types the ones that are necessary? I understand why uint8 could be necessary, since a 3 channel image and values 0-255 is represented with 8 bits (2^8). But why float32 and why others not?

Upvotes: 0

Views: 865

Answers (0)

Related Questions