Giter VIP home page Giter VIP logo

Comments (1)

ziyuan-linn avatar ziyuan-linn commented on August 26, 2024

Hi @JimmyDevPasto, thank you for submitting this issue! The flipImage function is no longer supported in the newest version of ml5.

If you would like to continue using an older library version with support for flipImage, try version 0.12.2. In the HTML file, change the version number of ml5 in the script tag from 1.0.1 or latest to 0.12.2. The script tag should be changed to something like this:

<script src="https://unpkg.com/[email protected]/dist/ml5.min.js"></script>

This should bring back the flipImage function!


Below is some info if you decide to try the new version of the library.

The new version of the ml5 library handles the mirroring differently. The latest version of the p5.js library has a flipped option for videos, which automatically flips a video when it is displayed. The new ml5 models also have a flipped option when applicable, setting it to true will horizontally mirror the output landmarks/masks. Setting both options to true will correctly mirror both the video and the prediction output. Below is an example with handPose model.

In the HTML file, set p5 and ml5 to the latest versions:

<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.4/p5.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/ml5.min.js"></script>

The sketch:

let handPose;
let video;
let hands = [];

function preload() {
  // Load the handPose model
  handPose = ml5.handPose({ flipped: true }); // <----- setting flipped to true
}

function setup() {
  createCanvas(640, 480);
  // Create the webcam video and hide it
  video = createCapture(VIDEO, { flipped: true }); // <----- setting flipped to true
  video.size(640, 480);
  video.hide();
  // start detecting hands from the webcam video
  handPose.detectStart(video, gotHands);
}

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

  // Draw all the tracked hand points
  for (let i = 0; i < hands.length; i++) {
    let hand = hands[i];
    for (let j = 0; j < hand.keypoints.length; j++) {
      let keypoint = hand.keypoints[j];
      fill(0, 255, 0);
      noStroke();
      circle(keypoint.x, keypoint.y, 10);
    }
  }
}

// Callback function for when handPose outputs data
function gotHands(results) {
  // save the output to the hands variable
  hands = results;
}

from ml5-next-gen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.