如果你只想获得图像的 行数和列数,行:代表图像的高,列:代表图像的宽。如

src = cv.imread(“xxxxx”) 读取图片

image = src.shape 获取图片宽高及通道数
rows = image[0]
cols = image[1]

src.shape返回值为:(rows, cols, 通道数)

所以image[3]就是通道数

tongdao_nums = image[3]
from PIL import Image
import cv2
from skimage import io
 
def shape_size():
    img = cv2.imread('img_part.jpg')
    print(img.shape)  # h, w, c
    img1 = Image.open('img_part.jpg')
    print(img1.size)  # w, h
    img2 = io.imread('img_part.jpg')
    print(img2.shape)  # h, w, c
 
 
if __name__ == '__main__':
    shape_size()

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐