Υποενότητα 10.2: Βίντεο στο p5
Υποενότητα 10.2: Βίντεο στο p5
- Εισαγωγή video
- Εργασίες με video
- Συνάρτηση createCapture()
Συνάρτηση createCapture()
Η συνάρτηση createCapture() επιτρέπει στο p5.js να συνδεθεί με την προεπιλεγμένη κάμερα του υπολογιστή σας και έτσι να εμφανίσει το αποτέλεσμα στην οθόνη.
Μέσα σε αυτή τη λειτουργία, θα πρέπει να καθορίσουμε τον τύπο των μέσων. Σε αυτή την περίπτωση, αυτό είναι το βίντεο, έτσι γράφουμε createCapture(VIDEO)
Αν θέλουμε να εμφανίσουμε το βίντεο στον καμβά, χρησιμοποιούμε τη image() function.
Για να αποκρύψουμε το βίντεο που δημιουργήθηκε εκτός του στοιχείου καμβά, χρησιμοποιούμε nameofvideo.hide();.
Παράδειγμα
Ακολουθεί ένα παράδειγμα κώδικα όπου το p5.js χρησιμοποιεί την κάμερα σας:
let camVideo;
function setup(){
createCanvas(600,800);
// make the connection to the webcam
camVideo = createCapture('VIDEO');
//set background color
background(244,98,44);
}
function draw(){
}
Μπορείτε να δείτε το αποτέλεσμα του παραπάνω κώδικα here
Exercise
- Open your Visual Studio editor and the
p5yourNamefolder. - Open the file
ex812.jsin your editor and save it asex1023.js - Open the file
ex812.htmlin your editor and save it asex1023.html - In the
ex1023.htmlfile, update the link toex1023.jsfrom exersice812.js - Go to the
index.htmlfile and create, underModule 10, alinkto theex1023.htmlfile with the title "createCapture()".
Modify the ex1023.jsfile and use as a base the above example and the theory in order to hide the initial video that is outside the canvas and display the video only inside the canvas. You can see here an example.
let camVideo;
function setup(){
createCanvas(600,600);
// make the connection to the webcam
camVideo = createCapture('VIDEO');
background(244,98,44);
//hide initial video
camVideo.hide();
}
function draw(){
// display video on the canvas
image(camVideo,0,0);
}
Κάντε μια Git commit με το μήνυμα "createCapture()".
- Δείτε περισσότερα για την createCapture() function