Solvedimgaug Conversion from RGB to HSV and back fails with OpenCV 3.x

I get the following error every time I run code with

iaa.ChangeColorspace(from_colorspace="RGB", to_colorspace="HSV"), iaa.ChangeColorspace(from_colorspace="HSV", to_colorspace="RGB"),

The error is the following

cv2.error: OpenCV(3.4.2) /io/opencv/modules/imgproc/src/color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'CvtHelper'
regferencing this line

img_rgb = cv2.cvtColor(image, from_to_var)

Any idea for a Fix?

18 Answers

✔️Accepted Answer

cv2.imread('w1.jpg', 0) with flag 0 loads the image in grayscale mode and hence the conversion from BGR to RGB fails, because your loaded image does not have three channels. Try cv2.imread('w1.jpg', 1) instead.

Other Answers:

Hey, i met the same problem, but may be not the same as yours.
In my script, i use the relative path for imread which caused the problem, so i change the path (copy the image to current directory or use absolute path).

  • Befor:

img = cv2.imread("~/data/opencv-logo.png")
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

  • Which lead to the problem:

imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(3.4.2) /io/opencv/modules/imgproc/src/color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'CvtHelper'

  • Solution for my problem:
    img = cv2.imread("opencv-logo.png")

I hope it can help.

what was the error? May be I have the same one.

More Issues: