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

Uncaught (in promise) TypeError: ml5.flipImage is not a function #163

Open
JimmyDevPasto opened this issue Jun 26, 2024 · 1 comment
Open

Comments

@JimmyDevPasto
Copy link

Best regards, this ml5 function does not work, it worked fine a few days ago, something changed in the library, I bought the function from my code

function classifyVideo() { flippedVideo = ml5.flipImage(video); classifier.classify(flippedVideo, gotResult); flippedVideo.remove(); }

the error is: Uncaught (in promise) TypeError: ml5.flipImage is not a function
classifyVideo index.js:136
setup index.js:43
_setup p5.min.js:2
_runIfPreloadsAreDone p5.min.js:2
_decrementPreload p5.min.js:2
registerPreloads/e.prototype.ml5Init/</t[n]/< p5Utils.js:144
promise callbackregisterPreloads/e.prototype.ml5Init/</t[n] p5Utils.js:143
preload index.js:17
_start p5.min.js:2
g p5.min.js:2
[277]</< p5.min.js:2
promise callback
[277]< p5.min.js:2
a p5.min.js:2
a p5.min.js:2
[264]< p5.min.js:2
a p5.min.js:2
o p5.min.js:2
p5.min.js:2
p5.min.js:2
p5.min.js:2

@ziyuan-linn
Copy link
Member

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants