【发布时间】:2023-04-01 16:37:01
【问题描述】:
Can I determine the number of channels in cv::Mat Opencv 的答案为 OpenCV 1 回答了这个问题:您使用图像的Mat.channels() 方法。
但在 cv2(我使用的是 2.4.6)中,我拥有的图像数据结构没有 channels() 方法。我正在使用 Python 2.7。
代码sn-p:
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.
感谢您的帮助。
【问题讨论】:
标签: python image opencv channels