-
Notifications
You must be signed in to change notification settings - Fork 16
/
load_images.py
66 lines (58 loc) · 2 KB
/
load_images.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import cv2
import os
import glob
import numpy as np
CONTENT_DIR = "content/*.jpg"
STYLE_DIR = "style/*.jpg"
if os.name == 'nt':
clear = 'cls'
else:
clear = 'clear'
def load_content_image(shape=None):
while True:
os.system(clear)
print("Select content image")
print("--------------------")
content_dir_files = glob.glob(CONTENT_DIR)
for i, file in enumerate(glob.glob(CONTENT_DIR)):
print("[%d]. %s" %(i, file))
print('\n')
choice = int(input('Enter your choice number: '))
if choice < 0 or choice > len(content_dir_files)-1:
input("Choice must be >= 0 and <=%d. Press enter to continue"%(len(content_dir_files)-1,))
continue
content_image = cv2.imread(content_dir_files[choice])
content_image = cv2.cvtColor(content_image, cv2.COLOR_BGR2RGB)
content_image = content_image.astype(np.float64)
if content_image.shape[0] * content_image.shape[1] > 500*500:
if shape != None:
content_image = cv2.resize(content_image, (shape[1], shape[0]))
else:
if abs(content_image.shape[0]-content_image.shape[1]) > 50:
content_image = cv2.resize(content_image, None, fx=0.5, fy=0.5)
else:
content_image = cv2.resize(content_image, (500, 500))
break
return content_image
def load_style_image(shape=None):
while True:
os.system(clear)
print("Select style image")
print("------------------")
style_dir_files = glob.glob(STYLE_DIR)
for i, file in enumerate(glob.glob(STYLE_DIR)):
print("[%d]. %s" %(i, file))
print('\n')
choice = int(input('Enter your choice number: '))
if choice < 0 or choice > len(style_dir_files)-1:
input("Choice must be >= 0 and <=%d. Press enter to continue"%(len(style_dir_files)-1,))
continue
style_image = cv2.imread(style_dir_files[choice])
style_image = cv2.cvtColor(style_image, cv2.COLOR_BGR2RGB)
style_image = style_image.astype(np.float64)
if shape != None:
style_image = cv2.resize(style_image, (shape[1], shape[0]))
else:
style_image = cv2.resize(style_image, None, fx=0.5, fy=0.5)
break
return style_image