Opencv error -Unsupported depth of input image:
29,045
According to this answer https://stackoverflow.com/a/45956247/7683041, try:
img_float32 = np.float32(needed_multi_channel_img)
lab_image = cv.cvtColor(img_float32, cv.COLOR_RGB2HSV)
Related videos on Youtube

Author by
Danish Xavier
Updated on July 09, 2022Comments
-
Danish Xavier 5 months
I am trying to convert a normalised RGB image to HSV or LAB colour space. Here is the normalisation function:
here is the basic code
print ('original image shape: ', image.shape) print ('normlaised image shape: ', needed_multi_channel_img.shape) # Converting to LAB color space lab_image = cv.cvtColor(needed_multi_channel_img, cv.COLOR_RGB2HSV) cv.imshow('Lab_space.jpg',lab_image.astype('float32')) cv.waitKey(0) cv.destroyAllWindows()
Here is the output trace:
/home/centura/gitlab/Acne_model/Acne Model/rosaceaexperiment1.py:82: RuntimeWarning: invalid value encountered in true_divide norm.append(image[i,j,a]/rooted_matrix[i,j]) /home/centura/gitlab/Acne_model/Acne Model/rosaceaexperiment1.py:82: RuntimeWarning: divide by zero encountered in true_divide norm.append(image[i,j,a]/rooted_matrix[i,j]) original image shape: (375, 600, 3) normlaised image shape: (375, 600, 3) Traceback (most recent call last): File "/home/centura/gitlab/Acne_model/Acne Model/rosaceaexperiment1.py", line 121, in <module> lab_image = cv.cvtColor(needed_multi_channel_img, cv.COLOR_RGB2HSV) cv2.error: OpenCV(3.4.3) /io/opencv/modules/imgproc/src/color.hpp:257: error: (-2:Unspecified error) in function 'cv::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::Set<3, 4>; VDcn = cv::Set<3>; VDepth = cv::Set<0, 5>; cv::SizePolicy sizePolicy = (cv::SizePolicy)2u; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]' > Unsupported depth of input image: > 'VDepth::contains(depth)' > where > 'depth' is 6 (CV_64F)
For zero division error, I have replaced it with 0 and nan is also replaced with 0.
I also searched through StackOverflow but could not find any information to debug it. I do not understand the meaning of this error and how to rectify it.
-
Danish Xavier over 3 yearsis there a simple way to convert it to float32.
-
Miki over 3 yearslike any other numpy array, with
astype
-
Danish Xavier over 3 yearsi tried it
normal_image[:,:,0] = normal_image[:,:,0].astype(np.float32)
normal_image[:,:,1] = normal_image[:,:,1].astype(np.float32)
normal_image[:,:,2] = normal_image[:,:,2].astype(np.float32)
still the error persists. -
Mikiyour image type is
CV_64F
(float64
) which is not supported bycvtColor
function. Convert the image to an appropriate type, e.g.float32
-