画像解像度の検出と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