OpenCV图像处理——python批量缩放图片并存储,cv2.resize

OpenCV图像处理——python批量缩放图片并存储,cv2.resize,第1张

核心代码:以将480*480的8张图片缩小为300*300为例

import cv2
import numpy as np
import os

os.mkdir("D:/MNIST-master/data/img_resize")
for i in range(0,8):
    a=i+1
    b=i+1
    img_name = str(a)
    img = cv2.imread("C:/Users/10230/Desktop/resource_photo/"+img_name+".png")
    img2 = cv2.resize(img, (300, 300))
    # # 转换np数组格式
    # pix_img = np.array(img)
    # # 重新reshape图片
    # pix_img = pix_img.reshape(-1, 28, 28, 1)
    # # 查看reshape后的图片shape
    img_name2 = str(b)
    cv2.imwrite("D:/MNIST-master/data/img_resize/"+img_name2+".png", img2)

运行结果:

原图:

 

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/715089.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存