Skip to content

Commit 11cf24f

Browse files
committed
Fix loadeddata errors in bodypix examples
1 parent a41dcb0 commit 11cf24f

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

examples/javascript/BodyPix/BodyPix_Webcam/sketch.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ async function setup() {
1818
video = await getVideo();
1919
// load bodyPix with video
2020
bodypix = await ml5.bodyPix(options)
21-
// run the segmentation on the video, handle the results in a callback
22-
bodypix.segment(video, gotImage, options);
2321
}
2422

2523
// when the dom is loaded, call make();
2624
window.addEventListener('DOMContentLoaded', function() {
2725
setup();
2826
});
2927

28+
function videoReady() {
29+
// run the segmentation on the video, handle the results in a callback
30+
bodypix.segment(video, gotImage, options);
31+
}
3032

3133
function gotImage(err, result){
3234
if(err) {
@@ -48,6 +50,7 @@ async function getVideo(){
4850
videoElement.setAttribute("style", "display: none;");
4951
videoElement.width = width;
5052
videoElement.height = height;
53+
videoElement.onloadeddata = videoReady;
5154
document.body.appendChild(videoElement);
5255

5356
// Create a webcam capture

examples/p5js/BodyPix/BodyPix_Webcam/sketch.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ BodyPix
1111
let bodypix;
1212
let video;
1313
let segmentation;
14-
let img;
1514

1615
const options = {
1716
outputStride: 8, // 8, 16, or 32, default is 16
@@ -25,8 +24,12 @@ function preload() {
2524
function setup() {
2625
createCanvas(320, 240);
2726
// load up your video
28-
video = createCapture(VIDEO);
27+
video = createCapture(VIDEO, videoReady);
2928
video.size(width, height);
29+
30+
}
31+
32+
function videoReady() {
3033
bodypix.segment(video, gotResults);
3134
}
3235

examples/p5js/BodyPix/BodyPix_Webcam_Parts/sketch.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ BodyPix
1111
let bodypix;
1212
let video;
1313
let segmentation;
14-
let img;
1514

1615
const options = {
1716
outputStride: 8, // 8, 16, or 32, default is 16
@@ -26,15 +25,17 @@ function setup() {
2625
createCanvas(320, 240);
2726

2827
// load up your video
29-
video = createCapture(VIDEO);
28+
video = createCapture(VIDEO, videoReady);
3029
video.size(width, height);
3130
// video.hide(); // Hide the video element, and just show the canvas
3231

3332
// Create a palette - uncomment to test below
3433
createHSBPalette();
3534
// createRGBPalette();
3635
// createSimplePalette();
36+
}
3737

38+
function videoReady() {
3839
bodypix.segmentWithParts(video, gotResults, options);
3940
}
4041

0 commit comments

Comments
 (0)