Skip to content

Commit aba4b26

Browse files
authored
Merge branch 'main' into development
2 parents 937de40 + e56f40a commit aba4b26

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
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

examples/p5js/CartoonGAN/CartoonGan_WebCam/sketch.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ function preload() {
88

99
function setup() {
1010
createCanvas(320, 240);
11-
video = createCapture(VIDEO);
11+
video = createCapture(VIDEO, videoReady);
1212
video.size(320, 240);
13+
}
14+
15+
function videoReady() {
1316
cartoonGAN.generate(video, gotResults);
1417
}
1518

examples/p5js/ObjectDetector/ObjectDetector_COCOSSD_Video/sketch.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ let detections = [];
1515

1616
function setup() {
1717
createCanvas(640, 480);
18-
video = createCapture(VIDEO);
18+
video = createCapture(VIDEO, videoReady);
1919
video.size(640, 480);
2020
video.hide();
21+
}
22+
23+
function videoReady() {
2124
// Models available are 'cocossd', 'yolo'
2225
detector = ml5.objectDetector('cocossd', modelReady);
2326
}
@@ -37,8 +40,8 @@ function modelReady() {
3740
function draw() {
3841
image(video, 0, 0);
3942

40-
for (let i = 0; i < detections.length; i++) {
41-
let object = detections[i];
43+
for (let i = 0; i < detections.length; i += 1) {
44+
const object = detections[i];
4245
stroke(0, 255, 0);
4346
strokeWeight(4);
4447
noFill();

0 commit comments

Comments
 (0)