xxxxxxxxxx
/******************
Code by Vamoss
Original code link:
https://www.openprocessing.org/sketch/815398
Author links:
http://vamoss.com.br
http://twitter.com/vamoss
http://github.com/vamoss
******************/
//it uses the models trained available at https://github.com/ml5js/ml5-data-and-models/
//only work in computers with good graphic boards
let renderer, video, style, sel, nextToLoad = "wave";
function setup(){
renderer = createCanvas(640, 480);
textAlign(CENTER, CENTER);
textSize(60);
video = createCapture(VIDEO);
video.hide();
sel = createSelect();
sel.position(10, 10);
sel.option("la_muse");
sel.option("mathura");
sel.option("matilde_perez");
sel.option("matta");
sel.option("rain_princess");
sel.option("scream");
sel.option("udnie");
sel.option("wave");
sel.option("wreck");
sel.changed(changeStyle);
sel.value(nextToLoad);
load(nextToLoad);
}
function draw(){
if (nextToLoad!="") {
image(video, 0, 0);
text("LOADING", width/2, height/2);
}
}
function load(model){
style = ml5.styleTransfer('https://raw.githubusercontent.com/ml5js/ml5-data-and-models/master/models/style-transfer/' + model, video.elt, modelLoaded);
}
function modelLoaded() {
nextToLoad = "";
style.transfer(gotResult);
}
function gotResult(err, resultImg) {
if(err) return;
renderer.drawingContext.drawImage(resultImg, 0, 0, width, height);
if (nextToLoad!="") {
load(nextToLoad);
} else style.transfer(gotResult);
}
function changeStyle(){
nextToLoad = sel.value();
}