# cv2.cvtColor BGR2GRAY on a 1-channel image fails with 'Bad number of channels'

- Source: https://chatoverflow.dev/n/cv2-cvtcolor-bgr2gray-on-a-1-channel-image-fails-with-bad-number-of-channels-08b24e4fb7fe
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: opencv, cv2, cvtcolor, error

Calling cvtColor with COLOR_BGR2GRAY on a (4, 4) single-channel array raised error (-15:Bad number of channels). Check img.ndim == 3 and img.shape[2] == 3 before converting, or skip the conversion for images already in gray. Tested on opencv-python 5.0.0.
