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

Stylistic tweaks to example codes #149

Merged
merged 3 commits into from
Jun 21, 2024
Merged
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
4 changes: 2 additions & 2 deletions examples/bodyPose-blazePose-skeleton/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ function setup() {

// Start detecting poses in the webcam video
bodyPose.detectStart(video, gotPoses);
//get the skeleton connection information
// Get the skeleton connection information
connections = bodyPose.getSkeleton();
}

function draw() {
// Draw the webcam video
image(video, 0, 0, width, height);

//draw the skeleton connections
// Draw the skeleton connections
for (let i = 0; i < poses.length; i++) {
let pose = poses[i];
for (let j = 0; j < connections.length; j++) {
Expand Down
4 changes: 2 additions & 2 deletions examples/bodyPose-skeleton/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ function setup() {

// Start detecting poses in the webcam video
bodyPose.detectStart(video, gotPoses);
//get the skeleton connection information
// Get the skeleton connection information
connections = bodyPose.getSkeleton();
}

function draw() {
// Draw the webcam video
image(video, 0, 0, width, height);

//draw the skeleton connections
// Draw the skeleton connections
for (let i = 0; i < poses.length; i++) {
let pose = poses[i];
for (let j = 0; j < connections.length; j++) {
Expand Down
6 changes: 3 additions & 3 deletions examples/faceMesh-bounding-box/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ function setup() {
}

function draw() {
// draw the webcam video
// Draw the webcam video
image(video, 0, 0, width, height);

// draw the faces' bounding boxes
// Draw the faces' bounding boxes
for (let i = 0; i < faces.length; i++) {
let face = faces[i];
let x = face.box.xMin;
Expand All @@ -44,7 +44,7 @@ function draw() {
rect(x, y, w, h);
text(i, x, y - 10);

// draw the center of the face
// Draw the center of the face
noStroke();
fill(255, 0, 0);
circle(centerX, centerY, 10);
Expand Down
4 changes: 2 additions & 2 deletions examples/imageClassifier-single-image/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ function setup() {
image(img, 0, 0, width, height);
}

// A function to run when we get any errors and the results
// Callback function for when classification has finished
function gotResult(results) {
// The results are in an array ordered by confidence, print in console
// The results are in an array ordered by confidence
console.log(results);

// Display the results on the canvas
Expand Down
2 changes: 1 addition & 1 deletion examples/imageClassifier-teachable-machine/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ function draw() {

// A function to run when we get the results
function gotResult(results) {
// update label variable which is displayed on the canvas
// Update label variable which is displayed on the canvas
label = results[0].label;
}
8 changes: 4 additions & 4 deletions examples/imageClassifier-webcam/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ function setup() {
}

function draw() {
//Each video frame is painted on the canvas
// Each video frame is painted on the canvas
image(video, 0, 0);

//Printing class with the highest probability on the canvas
// Printing class with the highest probability on the canvas
fill(255);
textSize(32);
text(label, 20, 50);
}

// A function to run when we get the results and any errors
// Callback function for when classification has finished
function gotResult(results) {
//update label variable which is displayed on the canvas
// Update label variable which is displayed on the canvas
label = results[0].label;
}
14 changes: 7 additions & 7 deletions examples/sentiment/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@ let inputBox;
let sentimentResult;

function preload() {
// Initialize the sentiment analysis model
sentiment = ml5.sentiment("MovieReviews");
}

function setup() {
noCanvas();
// initialize sentiment analysis model

// setup the html dom elements
// Setup the DOM elements
inputBox = createInput("Today is the happiest day and is full of rainbows!");
inputBox.attribute("size", "75");
submitBtn = createButton("submit");
sentimentResult = createP("Sentiment confidence:");

// predicting the sentiment when submit button is pressed
// Start predicting when the submit button is pressed
submitBtn.mousePressed(getSentiment);
}

function getSentiment() {
// get the values from the input
// Use the value of the input box
let text = inputBox.value();

// make the prediction
// Start making the prediction
sentiment.predict(text, gotResult);
}

function gotResult(prediction) {
// display sentiment result on html page
// Display sentiment result via the DOM
sentimentResult.html("Sentiment confidence: " + prediction.confidence);
}

// predicting the sentiment when 'Enter' key is pressed
// Start predicting when the Enter key is pressed
function keyPressed() {
if (keyCode == ENTER) {
getSentiment();
Expand Down