cherrydata / tools /test_channel.py
Voidljc
Your commit message
aa24fe8
Raw
History Blame Contribute Delete
649 Bytes
# import cv2
# # 读取图片
# img = cv2.imread("/home/lab/LJ/wampee/Wampee_dataSets__Voc_Sec/JPEGImages/2024_07_10_09_47_IMG_9327_part1.png")
# print("图片 shape:", img.shape) # 例如 (height, width, channels)
from PIL import Image
# 打开图片
img = Image.open("/home/lab/LJ/wampee/Wampee_dataSets__Voc_Sec/JPEGImages/2024_07_10_09_47_IMG_9327_part1.png")
# 打印图片模式
print("图片模式:", img.mode)
# 根据模式判断通道数
if img.mode == "RGB":
channels = 3
elif img.mode == "RGBA":
channels = 4
elif img.mode == "L":
channels = 1
else:
channels = "未知"
print("图片通道数:", channels)