Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opencv error -Unsupported depth of input image:

I am trying to convert a normalised RGB image to HSV or LAB colour space. Here is the normalisation function:enter image description here

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.

like image 715
Danish Xavier Avatar asked Mar 15 '19 09:03

Danish Xavier


2 Answers

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)
like image 67
PJ127 Avatar answered Nov 10 '22 16:11

PJ127


I actually had a similar issue, the problem was that the input was in floats but it was expecting integers. when i converted to integers (.astype('int')) this error disappeared. maybe I'll help you too.

like image 1
ArieAI Avatar answered Nov 10 '22 15:11

ArieAI