-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.py
45 lines (33 loc) · 1 KB
/
demo.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
import cv2
from PIL import Image
import numpy as np
import hydra
from controller import Controller
@hydra.main('config.yml')
def main(cfg):
def ratio(x):
pass
cv2.namedWindow('style transfer morphing')
cv2.createTrackbar('alpha', 'style transfer morphing', 0, 100, ratio)
cap = cv2.VideoCapture(0)
controller = Controller(
cfg.vgg_weight,
cfg.decoder_weight,
)
style = Image.open(cfg.style)
while True:
alpha = cv2.getTrackbarPos('alpha', 'style transfer morphing') / 100
ret, frame = cap.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = Image.fromarray(frame)
out = controller.transfer(img, style, alpha, cfg.resolution)
out = np.array(out, dtype=np.uint8)
out = cv2.cvtColor(out, cv2.COLOR_RGB2BGR)
cv2.imshow('style transfer', out)
k = cv2.waitKey(1)
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
main()