1 Star 1 Fork 1

织女的牛郎/tfrecord_generator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
resize.py 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
peiyuan.luo 提交于 2018-04-16 14:51 . init
#!/usr/bin/env python
# encoding: utf-8
"""
Usage:
# Script to resize all files in current directory,
saving new .jpg images in a new folder.
# eg. python resize.py
"""
import cv2
import glob
import os
import sys
import argparse
max_size = 512
folder = 'resized'
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--max_size", type=int, default=max_size,
help="the maximal image width/height")
parser.add_argument("-d", "--dest", default=folder,
help="destitation folder for resized images")
args = parser.parse_args()
max_size, folder = args.max_size, args.dest
def resize():
# find all jpg images
imgs = glob.glob('*.jpg')
print('Found files:')
print(imgs)
print('Resizing all images be %d pixels wide or height' % max_size)
if not os.path.exists(folder):
os.makedirs(folder)
# Iterate through resizing and saving
for img in imgs:
pic = cv2.imread(img, cv2.IMREAD_UNCHANGED)
ht, wd = pic.shape[0], pic.shape[1]
print(img, wd, ht)
if wd >= ht:
width = max_size
height = int(width * ht / wd)
else:
height = max_size
width = int(height * wd / ht)
pic = cv2.resize(pic, (width, height))
cv2.imwrite(folder + '/' + img, pic)
if __name__ == "__main__":
resize()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/leoluopy/tfrecord_generator.git
git@gitee.com:leoluopy/tfrecord_generator.git
leoluopy
tfrecord_generator
tfrecord_generator
master

搜索帮助