Python OpenCV 将给定目录内所有图像缩放

来源:互联网 发布:php 文章管理系统 编辑:程序博客网 时间:2024/06/06 02:41
import osimport cv2import sysimport numpy as npprint "resize images in this folder:"path = "/home/qz/Desktop/rgb/"print pathfor filename in os.listdir(path):    if os.path.splitext(filename)[1] == '.png':        print filename        img = cv2.imread(path + filename)        print np.shape(img)[0],np.shape(img)[1],np.shape(img)[2]        newImg = cv2.resize(img,dsize=(1440,1920))        # newImg = cv2.resize(img, dsize=(int((np.shape(img)[1])*0.2), int((np.shape(img)[0])*0.2)))        print np.shape(newImg)[0], np.shape(newImg)[1], np.shape(newImg)[2]        # cv2.namedWindow("Image")        # cv2.imshow("Image",newImg)        # cv2.waitKey(0)        cv2.imwrite(path + filename,newImg)

缩放后会将原图覆盖