图片分辨率检测与更改Python代码

前言

本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理。

PS:如有需要Python学习资料的小伙伴可以点击下方链接自行获取

Python免费学习资料、代码以及交流解答点击即可加入


检测:

'''
如有需要Python学习资料的小伙伴可以加群领取:1136201545
'''

import cv2
path = "D:/picture/source_image.png"
img = cv2.imread(path)
sp = img.shape
height = sp[0]  # height(rows) of image
width = sp[1]  # width(colums) of image
chanael = sp[2]  # the pixels value is made up of three primary colors
print ( 'width: %d \nheight: %d \nnumber: %d' % (width, height, chanael))

更改:


from PIL import Image
import os.path
import glob
def convertjpg(jpgfile,outdir,width=1280,height=720):
    img=Image.open(jpgfile)
    try:
        new_img=img.resize((width,height),Image.BILINEAR)
        new_img.save(os.path.join(outdir,os.path.basename(jpgfile)))
    except Exception as e:
        print(e)
for jpgfile in glob.glob("D:/picture/source_image.png"):
    convertjpg(jpgfile,"D:/picture/")

猜你喜欢

转载自blog.csdn.net/pythonxuexi123/article/details/114882856