Python ,利用cv2批量缩放图像

先将图像文件名称读取保存为csv文件,以下为读取文件夹下后缀为.py的文件名称的代码

#print(root) #当前目录路径  
#print(dirs) #当前路径下所有子目录  
#print(files) #当前路径下所有非目录子文件 
import os
import csv

L=[]   
file_dir ='.'
i=0
with open('predict.csv','w') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(['label'])
    for root, dirs, files in os.walk(file_dir): 
        for file in files:  
            if os.path.splitext(file)[1]=='.py':
                L.append (os.path.join(file))
                csvfile.write('\n'.join(L))

批量缩放文件夹下的图像

import os
import cv2
import numpy as np
import sys
import csv
import pandas as pd    
colunm=[]
with open('E:/skin_2018/Training_GroundTruth/1.csv','rt',encoding='utf-8') as csvfile:
    reader = csv.DictReader(csvfile)
    column = [row['image'] for row in reader]


for i in column:
    img=cv2.imread('E:/2018/Task3_Training_Input/'+i+'.jpg')
    np.shape(img)
    img1 = cv2.resize(img,(256,256))
    cv2.imwrite('E:/2018/2018_256/'+i+'.jpg',img1)

print (over)
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页