Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #1417

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/p5js/UNET/UNET_Image/assets/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions examples/p5js/UNET/UNET_Image/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
<meta charset="UTF-8" >
<title>UNET example with p5.js</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ml5.min.js" type="text/javascript"></script>
</head>

<body>
<h1>UNET Image example using p5.js</h1>
<script src="sketch.js"></script>
</body>
</html>
51 changes: 51 additions & 0 deletions examples/p5js/UNET/UNET_Image/sketch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2022 ml5
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

/* ===
ml5 Example
UNET Image example using p5.js
=== */

let video;
let uNet;
let segmentationImage;

// load uNet model
function preload() {
uNet = ml5.uNet('face');
}

function setup() {
createCanvas(320, 240);

// load up your image
img = createImg("assets/test.png", imageReady);
img.hide();

//create blank image
segmentationImage = createImage(width, height);
frameRate(1);
}

function imageReady(){
console.log('Image ready');

uNet.segment(img, gotResult);
}

function gotResult(error, result) {
// if there's an error return it
if (error) {
console.error(error);
return;
}
// set the result to the global segmentation variable
segmentationImage = result.backgroundMask;
}

function draw() {
background(0)
image(segmentationImage, 0, 0, width, height);
}