imgaug: 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 https://github.com/aleju/imgaug/blob/1887d1e5bb2afa8ce94320f4bc7ab354753e9eda/imgaug/augmenters/color.py#L341

Any idea for a Fix?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (1 by maintainers)

Most upvoted comments

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.

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.

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

img1 = cv2.imread(‘w1.jpg’,0) edges1=cv2.Canny(img1,100,200) img_a=cv2.cvtColor(img1,cv2.COLOR_BGR2RGB)

The error is: Invalid number of channels in input image:

'VScn::contains(scn)'

where ‘scn’ is 1

please tell me what is scn

Sorry I didn’t have to change any code, I simply stopped feeding the masks to the augmentator and only fed it images with 3 channels, and the error stopped showing up

I was trying to augment some images that had 7 channels with those augmenters (they were masks I needed to train my neural network). So obviously an error was thrown saying that my image didn’t look like an image and it didn’t know what to interpret as R G and B

Hi @cicobalico What was the error?