From 9204d28650c86fb3bbc48f66b316a0fa4ba234db Mon Sep 17 00:00:00 2001 From: bio-punk Date: Thu, 24 Jan 2019 20:41:13 +0800 Subject: =?UTF-8?q?=E7=94=A8python=E5=92=8Copencv=E5=86=99=E4=BA=86?= =?UTF-8?q?=E4=B8=AA=E5=8E=8B=E7=BC=A9=E5=9B=BE=E7=89=87=E7=9A=84=EF=BC=8C?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=8E=8B=E7=BC=A9=E5=88=B01366=E7=9A=84jpg?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=20=E5=8E=8B=E7=BC=A9=E4=BA=86=E5=8E=9F?= =?UTF-8?q?=E6=9D=A5=E7=9A=84=E7=85=A7=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bio-punk/zipPhoto.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Bio-punk/zipPhoto.py (limited to 'Bio-punk/zipPhoto.py') diff --git a/Bio-punk/zipPhoto.py b/Bio-punk/zipPhoto.py new file mode 100644 index 0000000..5036255 --- /dev/null +++ b/Bio-punk/zipPhoto.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +import cv2 +from os import listdir +from re import match +from re import I as flag +import numpy as np + +def resize_width(image, width=1200): + power = width * 1.0 / image.shape[1] + dim = (width, int(image.shape[0] * power)) + resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA) + return resized + +def zip_photo(filepath): + targetWidth = 1366 + image = cv2.imread(filepath) + if image.shape[0] > targetWidth: + image = resize_width(image=image, width = targetWidth) + cv2.imwrite("{}.jpg".format(filepath), image) + +dirpath = "." +for filename in listdir(dirpath): + ans = match("^(.*)[.]((png)|(bmp)|(jpg)|(jpeg))$", filename, flag) + if ans is not None: + print (filename) + zip_photo("{}/{}".format(dirpath, filename)) \ No newline at end of file -- cgit v1.2.3