【python】图像数据集处理1
自学笔记
1 遍历目录内所有内容获取地址——glob.glob()
glob.glob(pathname, *, root_dir=None, dir_fd=None, recursive=False)
- pathname: 既可以是绝对路径( /usr/src/Python-1.5/Makefile),也可以是相对路径(…/…/Tools//.gif)。
- recursive:如果recursive为true,则模式“**”将匹配任何文件以及零个或多个目录、子目录和指向目录的符号链接。
- 例子:
2 计数并返回字典——Counter()
counts = Counter(k) # 输入的k为字典
counts.keys() # 标签名
counts.values() # 统计数值
3 循环中枚举index和value——enumerate()
s = [1, 2, 3, 4, 5]
x = enumerate(s)
for index,value in x:
print("%s,%s"%(index,value))
# 0,1
# 1,2
# 2,3
# 3,4
# 4,5
4 随机数——random.randint()
import random
num = random.randint(10, 20)
5 图像裁剪
cropped_image = image[ymin:ymax, xmin:xmax] # 图像裁剪