如何在 python 中找到 gdal 中的波段数?

How to find the number of bands in gdal in python?

我正在使用下面的代码读取 tiff 数据。

ds = 'path' , gdal.GA_ReadOnly)

我找到了 gdal API,我找不到读取波段的数量。

(ex) 我有一个 3 波段图像,然后读取波段数和 return 3 以防万一)

有什么方法可以找到波段数吗?

RasterCount 属性给出波段数。 这是一个简单的例子:

src_ds = gdal.Open("INPUT.tif")
if src_ds is not None: 
    print ("band count: " + str(src_ds.RasterCount))