forked from maltseasy/faststyletransfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
113 lines (96 loc) · 2.86 KB
/
sketch.js
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
let style;
let video;
let isTransferring = false;
let resultImg;
function setup() {
createCanvas(320, 240).parent('canvasContainer');
video = createCapture(VIDEO);
video.hide();
// The results image from the style transfer
resultImg = createImg('');
resultImg.hide();
// The button to start and stop the transfer process
select('#startStop').mousePressed(startStop);
// Create a new Style Transfer method with a defined style.
// We give the video as the second argument
style = ml5.styleTransfer('models/mathura', video, modelLoaded);
}
function draw(){
// Switch between showing the raw camera or the style
if (isTransferring) {
image(resultImg, 0, 0, 320, 240);
} else {
image(video, 0, 0, 320, 240);
}
}
// A function to call when the model has been loaded.
function modelLoaded() {
select('#status').html('Model Loaded');
}
function selectmathura(){
console.log("mathura")
select('#startStop').html('Stop');
isTransferring = false;
style = ml5.styleTransfer('models/mathura', video, modelLoaded);
select('#startStop').html('Start');
}
function selectrainprincess(){
console.log("rainprincess")
select('#startStop').html('Stop');
isTransferring = false;
style = ml5.styleTransfer('models/rain_princess', video, modelLoaded);
select('#startStop').html('Start');
}
function selectscream(){
console.log("scream")
select('#startStop').html('Stop');
isTransferring = false;
style = ml5.styleTransfer('models/scream', video, modelLoaded);
select('#startStop').html('Start');
}
function selectudnie(){
console.log("udnie")
select('#startStop').html('Stop');
isTransferring = false;
style = ml5.styleTransfer('models/udnie', video, modelLoaded);
select('#startStop').html('Start');
}
function selectwave(){
console.log("wave")
select('#startStop').html('Stop');
isTransferring = false;
style = ml5.styleTransfer('models/wave', video, modelLoaded);
select('#startStop').html('Start');
}
function selectwreck(){
console.log("wreck")
select('#startStop').html('Stop');
isTransferring = false;
style = ml5.styleTransfer('models/wreck', video, modelLoaded);
select('#startStop').html('Start');
}
function selectzhang(){
console.log("zhang")
select('#startStop').html('Stop');
isTransferring = false;
style = ml5.styleTransfer('models/zhangdaqian', video, modelLoaded);
select('#startStop').html('Start');
}
// Start and stop the transfer process
function startStop() {
if (isTransferring) {
select('#startStop').html('Start');
} else {
select('#startStop').html('Stop');
// Make a transfer using the video
style.transfer(gotResult);
}
isTransferring = !isTransferring;
}
// When we get the results, update the result image src
function gotResult(err, img) {
resultImg.attribute('src', img.src);
if (isTransferring) {
style.transfer(gotResult);
}
}