Skip to content

Commit 8850c03

Browse files
committed
Add legacy example update scripts
Fixed ml5js/ml5-website-v02-docsify#167
1 parent b118fe7 commit 8850c03

File tree

422 files changed

+8395
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

422 files changed

+8395
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
P5_USERNAME=ml5
2+
P5_PASSWORD=********

legacy-example-updates/.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.env
2+
dev
3+
examples/es6/node_modules
4+
experiments/node_modules
5+
node_modules
6+
**/npm-debug.log
7+
*.DS_STORE
8+
experiments
9+
manual-test
10+
training/lstm/data/t
11+
.cache
12+
/public
13+
/static
14+
dist
15+
/dist_examples
16+
.yarn
17+
18+
website/translated_docs
19+
website/build/
20+
website/yarn.lock
21+
website/node_modules
22+
23+
website/i18n/*
24+
!website/i18n/en.json
25+
26+
yarn-error.log
27+
local.log
28+
29+
tests/coverage/*
102 KB
Loading
80.2 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<html>
2+
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>BodyPix with Image</title>
6+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
7+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
8+
<script src="https://unpkg.com/ml5@0.12.2/dist/ml5.min.js"></script>
9+
10+
<style></style>
11+
</head>
12+
13+
<script src="sketch.js"></script>
14+
15+
<body>
16+
<h1>BodyPix with Image</h1>
17+
<small>images via: https://commons.wikimedia.org</small>
18+
19+
</body>
20+
21+
</html>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2020 ml5
2+
//
3+
// This software is released under the MIT License.
4+
// https://opensource.org/licenses/MIT
5+
6+
/* ===
7+
ml5 Example
8+
BodyPix
9+
=== */
10+
11+
let bodypix;
12+
let segmentation;
13+
let img;
14+
15+
function preload() {
16+
img = loadImage('data/harriet.jpg');
17+
bodypix = ml5.bodyPix();
18+
}
19+
20+
function setup() {
21+
createCanvas(480, 560);
22+
bodypix.segment(img, gotResults);
23+
}
24+
25+
function gotResults(err, result) {
26+
if (err) {
27+
console.log(err);
28+
return;
29+
}
30+
segmentation = result;
31+
background(0);
32+
image(segmentation.backgroundMask, 0, 0, width, height);
33+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>BodyPix with Webcam</title>
6+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
7+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
8+
<script src="https://unpkg.com/ml5@0.12.2/dist/ml5.min.js"></script>
9+
10+
<style></style>
11+
</head>
12+
13+
<script src="sketch.js"></script>
14+
15+
<body>
16+
<h1>BodyPix with Webcam</h1>
17+
</body>
18+
19+
</html>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2020 ml5
2+
//
3+
// This software is released under the MIT License.
4+
// https://opensource.org/licenses/MIT
5+
6+
/* ===
7+
ml5 Example
8+
BodyPix
9+
=== */
10+
11+
let bodypix;
12+
let video;
13+
let segmentation;
14+
15+
const options = {
16+
outputStride: 8, // 8, 16, or 32, default is 16
17+
segmentationThreshold: 0.3, // 0 - 1, defaults to 0.5
18+
};
19+
20+
function preload() {
21+
bodypix = ml5.bodyPix(options);
22+
}
23+
24+
function setup() {
25+
createCanvas(320, 240);
26+
// load up your video
27+
video = createCapture(VIDEO, videoReady);
28+
video.size(width, height);
29+
30+
}
31+
32+
function videoReady() {
33+
bodypix.segment(video, gotResults);
34+
}
35+
36+
function draw() {
37+
background(0);
38+
if (segmentation) {
39+
image(segmentation.backgroundMask, 0, 0, width, height);
40+
}
41+
}
42+
43+
function gotResults(error, result) {
44+
if (error) {
45+
console.log(error);
46+
return;
47+
}
48+
segmentation = result;
49+
bodypix.segment(video, gotResults);
50+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>BodyPix with Webcam</title>
6+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
7+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
8+
<script src="https://unpkg.com/ml5@0.12.2/dist/ml5.min.js"></script>
9+
10+
<style></style>
11+
</head>
12+
13+
<script src="sketch.js"></script>
14+
15+
<body>
16+
<h1>BodyPix with Webcam and Part Segmentation</h1>
17+
</body>
18+
19+
</html>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright (c) 2020 ml5
2+
//
3+
// This software is released under the MIT License.
4+
// https://opensource.org/licenses/MIT
5+
6+
/* ===
7+
ml5 Example
8+
BodyPix
9+
=== */
10+
11+
let bodypix;
12+
let video;
13+
let segmentation;
14+
15+
const options = {
16+
outputStride: 8, // 8, 16, or 32, default is 16
17+
segmentationThreshold: 0.3, // 0 - 1, defaults to 0.5
18+
};
19+
20+
function preload() {
21+
bodypix = ml5.bodyPix(options);
22+
}
23+
24+
function setup() {
25+
createCanvas(320, 240);
26+
27+
// load up your video
28+
video = createCapture(VIDEO, videoReady);
29+
video.size(width, height);
30+
// video.hide(); // Hide the video element, and just show the canvas
31+
32+
// Create a palette - uncomment to test below
33+
createHSBPalette();
34+
// createRGBPalette();
35+
// createSimplePalette();
36+
}
37+
38+
function videoReady() {
39+
bodypix.segmentWithParts(video, gotResults, options);
40+
}
41+
42+
function gotResults(err, result) {
43+
if (err) {
44+
console.log(err);
45+
return;
46+
}
47+
segmentation = result;
48+
49+
background(255, 0, 0);
50+
// image(video, 0, 0, width, height)
51+
image(segmentation.partMask, 0, 0, width, height);
52+
53+
bodypix.segmentWithParts(video, gotResults, options);
54+
}
55+
56+
function createSimplePalette() {
57+
options.palette = bodypix.config.palette;
58+
Object.keys(bodypix.palette).forEach(part => {
59+
const r = floor(random(255));
60+
const g = floor(random(255));
61+
const b = floor(random(255));
62+
options.palette[part].color = [r, g, b];
63+
});
64+
}
65+
66+
function createHSBPalette() {
67+
colorMode(HSB);
68+
options.palette = bodypix.config.palette;
69+
Object.keys(options.palette).forEach(part => {
70+
const h = floor(random(360));
71+
const s = floor(random(100));
72+
const b = floor(random(100));
73+
const c = color(h, s, b);
74+
options.palette[part].color = c;
75+
});
76+
}
77+
78+
function createRGBPalette() {
79+
colorMode(RGB);
80+
options.palette = bodypix.config.palette;
81+
Object.keys(options.palette).forEach(part => {
82+
const r = floor(random(255));
83+
const g = floor(random(255));
84+
const b = floor(random(255));
85+
const c = color(r, g, b);
86+
options.palette[part].color = c;
87+
});
88+
}

0 commit comments

Comments
 (0)