python resize


import sys
import os
sys.path.append('/usr/local/lib/python2.7/site-packages')
sys.path.append('/usr/lib/python2.7/dist-packages')
import matplotlib.pyplot as plt
import cv2

def resizeimg(filename):
    img=cv2.imread(filename)
    shape=img.shape
    
    w=shape[1]
    h=shape[0]
    ww=w
    hh=h
    bresize=False
    if w > h and w > 800:
        ww=800
        hh=h/(w/800)
        bresize=True
    if h > w and h > 800:
        hh=800
        ww=w/(h/800)
        bresize=True
    if bresize:    
        print filename
        img=cv2.resize(img,(ww,hh))
        cv2.imwrite(filename,img)
    
for r, d, files in os.walk( '/var/Public/img/' ):
    for ffile in files:
        if ffile.endswith( 'jpg' ):
            resizeimg(r+'/'+ffile)

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM