-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
188 lines (155 loc) · 5.55 KB
/
test.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
from image.dlib_detector import DLIB_DETECTOR
from mtcnn import MTCNN
import cv2 as cv
def test_TwoImages():
from image.image import TwoImages
detector = MTCNN()
a = TwoImages(person_filename="human_pics/img.PNG",
comic_filename="comic_pics/ki.png", detector=detector)
im = a.compare()
cv.imshow("Face comparaison", im)
cv.waitKey(0)
cv.destroyAllWindows()
def test_rotateImage():
from image.image import Image
detector = DLIB_DETECTOR()
a = Image(path="comic_pics/ki.png", convert=True, detector=detector)
a.detect_face()
cv.imshow("Rotation", a.rotate_image())
cv.waitKey(0)
cv.destroyAllWindows()
def test_fusion():
from image.image import TwoImages
detector = DLIB_DETECTOR()
a = TwoImages(person_filename="human_pics/girl.jpg",
comic_filename="comic_pics/pretty_girl.png", detector=detector)
im = a.fusion(debug=True)
cv.imshow("Fusion", im)
cv.waitKey(0)
cv.destroyAllWindows()
def test_run_fusion():
from image.dlib_detector import DLIB_DETECTOR
import cv2 as cv
from image.image import TwoImages
detector = DLIB_DETECTOR()
a = TwoImages(person_filename="human_pics/img.PNG",
comic_filename="comic_pics/ki.png", detector=detector)
im = a.run(merge=True)
cv.imshow("Fusion", im)
cv.waitKey(0)
cv.destroyAllWindows()
print(a.person_image.isConverted)
print(a.comic_image.isConverted)
im = a.run(merge=False)
cv.imshow("Fusion", im)
cv.waitKey(0)
cv.destroyAllWindows()
def test_fusion_rotated():
from image.image import TwoImages
detector = DLIB_DETECTOR()
a = TwoImages(person_filename="human_pics/img.PNG",
comic_filename="comic_pics/ki.png", detector=detector)
im = a.fusion_rotated()
cv.imshow("Fusion_rotated", im)
cv.waitKey(0)
cv.destroyAllWindows()
def test_TwoImages_with_face():
from image.image import TwoImages
detector = DLIB_DETECTOR()
a = TwoImages(person_filename="human_pics/img.PNG",
comic_filename="face_pics/sensei.png", detector=detector)
im = a.compare()
cv.imshow("Face comparaison", im)
cv.waitKey(0)
cv.destroyAllWindows()
def test_with_face():
from image.image import TwoImages
detector = DLIB_DETECTOR()
a = TwoImages(person_filename="human_pics/img.PNG",
comic_filename="face_pics/sensei.png", detector=detector)
im = a.fusion(face_filename="face_pics/face_sensei.png")
cv.imshow("Fusion_rotated", im)
cv.waitKey(0)
cv.destroyAllWindows()
def test_with_face_rotated():
from image.image import TwoImages
a = TwoImages(person_filename="human_pics/img.PNG",
comic_filename="face_pics/sensei.png")
im = a.fusion_rotated(face_filename="face_pics/face_sensei.png")
cv.imshow("Fusion_rotated", im)
cv.imwrite("results/sensei.png", im)
cv.waitKey(0)
cv.destroyAllWindows()
def preprocess():
import os
from image.image import Image
g = os.walk(r"comic_pics")
for path, dir_list, file_list in g:
for file_name in file_list:
path_tmp = os.path.join(path, file_name)
print(path_tmp)
a = Image(path=path_tmp, convert=True)
a.preprocess(path_tmp)
g = os.walk(r"face_pics")
for path, dir_list, file_list in g:
for file_name in file_list:
path_tmp = os.path.join(path, file_name)
print(path_tmp)
print("face" in file_name)
if "face" in file_name:
continue
a = Image(path=path_tmp, convert=True)
face_path = path + r"/face_" + file_name
a.preprocess(path_tmp, face_path=face_path)
def test_video():
from image.video import Video
a = Video(video_path="video/test_Trim.mp4", comic_path="comic_pics/ki.png")
a.process_video()
def test_color_transfer():
from image.image import TwoImages
import cv2 as cv
detector = DLIB_DETECTOR()
a = TwoImages(person_filename="human_pics/img.PNG",
comic_filename="comic_pics/ki2.png", detector=detector)
im = a.run(rotate=True, merge=True)
cv.imshow("rotate and merge", im)
cv.imwrite("results/ki_merge.png", im)
cv.waitKey(0)
cv.imwrite("result/color_transfer.png", im)
def test_cycle_gan():
import numpy as np
from keras.models import load_model
from image.cycleGAN import load_image, arr2image
model = load_model('gan_input/model/GA.h5')
image_size = 128
a, shape = load_image("human_pics/img.PNG", image_size)
a = np.array([a])
b = arr2image(model.predict(a)[0])
b = b.resize(shape)
b.show()
b.save("results/gan_human2comic.jpg")
model = load_model('gan_input/model/GB.h5')
a, shape = load_image("face_pics/ki.png", image_size)
a = np.array([a])
b = arr2image(model.predict(a)[0])
b = b.resize(shape)
b.show()
b.save("results/gan_comic2human.jpg")
def test_virtual_camera():
import pyvirtualcam
import numpy as np
with pyvirtualcam.Camera(width=1280, height=720, fps=24) as cam:
i = 0
while True:
print(i)
i = i + 1
frame = np.zeros((cam.height, cam.width, 4), np.uint8) # RGBA
frame[:, :, :3] = cam.frames_sent % 255 # grayscale animation
frame[:, :, 3] = 255
cam.send(frame)
cam.sleep_until_next_frame()
def test_jojo_camera():
from image.video import VirtualCamera
v = VirtualCamera(comic_path="comic_pics/ki.png")
v.run(merge=False, warpH=True)
test_fusion()