-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
33 lines (26 loc) · 839 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import cv2
import glob
import os
import imutils
from pathlib import Path
def thumbnail(file,save_path):
try:
Path(os.path.dirname(save_path)).mkdir(parents=True, exist_ok=True)
save_name=os.path.basename(file)
print(file,save_path,save_name)
if not file.startswith("http://"):
original = cv2.imread(file)
else:
original = imutils.url_to_image(file)
if original is None:
print("Not able to read",file)
return False
height, width, channels = original.shape
if height > width:
im=imutils.resize(original,width=400)
else:
im=imutils.resize(original,width=600)
cv2.imwrite(os.path.join(save_path,save_name), im)
return True
except Exception as e:
raise e