image_resize.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:visual-search 作者: GYXie 项目源码 文件源码
def main():
    print(args)
    for dir_path, dir_names, file_names in os.walk(args.input_data_dir):
        # dir_path is a string, the path to the directory
        # dir_names is a list of the names of the subdirectories in dir_path (excluding '.' and '..')
        # file_names is a list of the names of the non-directory files in dir_path
        dir_absolute_path = args.output_data_dir + dir_path.replace(args.input_data_dir, '')
        if not os.path.exists(dir_absolute_path):
            os.mkdir(dir_absolute_path)
        for file_name in file_names:
            # Split the pathname path into a pair (root, ext) such that root + ext == path, and ext is empty or begins
            # with a period and contains at most one period.
            (root, ext) = os.path.splitext(file_name)
            new_file_name = '%s/%s.%dx%d%s' % (
                dir_absolute_path, root, args.width, args.height, ext)
            print(new_file_name)
            if not os.path.exists(new_file_name):
                img = imread(dir_path + '/' + file_name)
                # type(img) = ndarray, https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html
                (width, height) = img.shape[0:2]
                if width > height:
                    size = (args.width, height * args.width / width)
                else:
                    size = (width * args.height / height, args.height)
                new_img = misc.imresize(img, size)
                misc.imsave(new_file_name, new_img)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号