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

move YOLO examples into ObjectDetector #1415

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
2 changes: 1 addition & 1 deletion examples/examples.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

/* ===
ml5 Example
Real time Object Detection using objectDetector
Real time Object Detection using COCOSSD
=== */

let objectDetector;
let status;
let objects = [];
let canvas, ctx;
let img;
let canvas;
let ctx;
const width = 640;
const height = 420;

Expand Down Expand Up @@ -78,4 +79,4 @@ function createCanvas(w, h) {
canvas.height = h;
document.body.appendChild(canvas);
return canvas;
}
}
8 changes: 4 additions & 4 deletions examples/javascript/ObjectDetector/COCOSSD_webcam/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

/* ===
ml5 Example
Real time Object Detection using objectDetector
Real time Object Detection using COCOSSD
=== */

let objectDetector;
let status;
let objects = [];
let video;
let canvas, ctx;
let canvas;
let ctx;
const width = 480;
const height = 360;

Expand Down Expand Up @@ -95,4 +95,4 @@ function createCanvas(w, h){
canvas.height = h;
document.body.appendChild(canvas);
return canvas;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

/* ===
ml5 Example
Real time Object Detection using objectDetector
Real time Object Detection using YOLO
=== */

let objectDetector;
let status;
let img;
let objects = [];
let canvas, ctx;
let canvas;
let ctx;
const width = 640;
const height = 420;

Expand Down Expand Up @@ -78,4 +79,4 @@ function createCanvas(w, h){
canvas.height = h;
document.body.appendChild(canvas);
return canvas;
}
}
8 changes: 4 additions & 4 deletions examples/javascript/ObjectDetector/YOLO_webcam/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

/* ===
ml5 Example
Real time Object Detection using objectDetector
Real time Object Detection using YOLO
=== */

let objectDetector;
let status;
let objects = [];
let video;
let canvas, ctx;
let canvas;
let ctx;
const width = 480;
const height = 360;

Expand Down Expand Up @@ -93,4 +93,4 @@ function createCanvas(w, h){
canvas.height = h;
document.body.appendChild(canvas);
return canvas;
}
}
16 changes: 0 additions & 16 deletions examples/javascript/YOLO/YOLO_single_image/index.html

This file was deleted.

81 changes: 0 additions & 81 deletions examples/javascript/YOLO/YOLO_single_image/sketch.js

This file was deleted.

15 changes: 0 additions & 15 deletions examples/javascript/YOLO/YOLO_webcam/index.html

This file was deleted.

97 changes: 0 additions & 97 deletions examples/javascript/YOLO/YOLO_webcam/sketch.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* ===
ml5 Example
Object Detection using YOLO
=== */

let objects = [];
let objectDetector;
let img;

// Load the image before the main program starts.
function preload() {
img = loadImage("images/cat2.JPG");
}

function setup() {
// Create a canvas that's the size of the image.
createCanvas(img.width, img.height);
// Draw the image to the canvas.
image(img, 0, 0);
// Create the model and call modelReady() when it is loaded.
// Models available are 'cocossd', 'yolo'.
objectDetector = ml5.objectDetector("yolo", modelReady);
}

// When the model is ready, do the detection.
function modelReady() {
console.log("Model ready!");
objectDetector.detect(img, gotResult);
}

// A function to run when we get any errors and the results
function gotResult(err, results) {
if (err) {
console.log(err);
return;
}
console.log(results);
// Assign the results to the global `objects` variable to be used in draw().
objects = results;
}

function draw() {
// Check that we have results.
if (objects.length > 0) {
for (let i = 0; i < objects.length; i += 1) {
noStroke();
fill(0, 255, 0);
text(
`${objects[i].label} ${nfc(objects[i].confidence * 100.0, 2)}%`,
objects[i].x + 5,
objects[i].y + 15,
);
noFill();
strokeWeight(4);
stroke(0, 255, 0);
rect(
objects[i].x,
objects[i].y,
objects[i].width,
objects[i].height,
);
}
noLoop(); // Stops the p5 loop so that draw() won't be called again.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function setup() {
video = createCapture(VIDEO);
video.size(320, 240);

// Create a YOLO method
yolo = ml5.YOLO(video, startDetecting);
// Create an ObjectDetector using YOLO as the model
yolo = ml5.objectDetector('yolo', video, startDetecting);

// Hide the original video
video.hide();
Expand Down
Binary file removed examples/p5js/YOLO/YOLO_single_image/images/cat.JPG
Binary file not shown.
Binary file removed examples/p5js/YOLO/YOLO_single_image/images/cat2.JPG
Binary file not shown.
Binary file not shown.
Loading