将图片大小统一成720p

功能:将图片大小统一成720p。

import os  
import io  
import math
import sys
import cv2
import shutil
import random
import numpy as np
from collections import namedtuple, OrderedDict  

def get_files(dir, suffix): 
    res = []
    for root, directory, files in os.walk(dir): 
        for filename in files:
            name, suf = os.path.splitext(filename) 
            if suf in suffix:
                #res.append(filename)
                res.append(os.path.join(root, filename))
    return res

def uniform_image_size(list_path,width_size,height_size):
    image_list = get_files(list_path, ['.jpg'])
    total_len = len(image_list)
    print('total_label_len', total_len)
    for i in range(0, total_len):
        image_file = image_list[i]
        img = cv2.imread(image_file)
        if img.shape[0] != height_size or img.shape[1] != width_size:
            img = cv2.resize(img, (width_size,height_size), interpolation=cv2.INTER_LINEAR)
            os.remove(image_file)
            cv2.imwrite(image_file, img)
        print('img.shape[0]',img.shape[0],'--------',image_file)
    random.shuffle(image_list)

def main():  
    list_path = r'E:\projection\fair\data\genarate_4to1\negative_image\101'
    width_size = 1280
    height_size = 720
    uniform_image_size(list_path,width_size,height_size)
    
if __name__ == '__main__':  
    main()
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值