当前位置 : 主页 > 编程语言 > python >

python resize

来源:互联网 收集:自由互联 发布时间:2022-06-15
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
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)





上一篇:python 直方图hist
下一篇:没有了
网友评论