The answers at Can I determine the number of channels in cv::Mat Opencv answer this question for OpenCV 1: you use the Mat.channels() method of the image.
I'm kind of late but there is another simple way out there:
Use image.ndim Source, will give your right number of channels as below:
if image.ndim == 2:
channels = 1 #single (grayscale)
if image.ndim == 3:
channels = image.shape[-1]
Since a image is a nothing but a numpy array. Checkout OpenCV docs here: docs