3
Can I determine the number of channels in cv::Mat Opencv回答這個問題有關OpenCV 1的問題:您使用圖像的Mat.channels()
方法。如何從OpenCV 2中的圖像獲取通道數量?
但是在cv2中(我使用的是2.4.6),我的圖像數據結構沒有channels()
方法。我正在使用Python 2.7。
代碼片段:
cam = cv2.VideoCapture(source)
ret, img = cam.read()
# Here's where I would like to find the number of channels in img.
互動的嘗試:
>>> img.channels()
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'channels'
>>> type(img)
<type 'numpy.ndarray'>
>>> img.dtype
dtype('uint8')
>>> dir(img)
['T',
'__abs__',
'__add__',
...
'transpose',
'var',
'view']
# Nothing obvious that would expose the number of channels.
感謝您的幫助。
正是我所需要的。謝謝! – LarsH