ml5-next-gen icon indicating copy to clipboard operation
ml5-next-gen copied to clipboard

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

Open JimmyDevPasto opened this issue 1 year ago • 1 comments

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

JimmyDevPasto avatar Jun 26 '24 23:06 JimmyDevPasto

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

ziyuan-linn avatar Jun 28 '24 17:06 ziyuan-linn

I'm going to go ahead and close this issue! We have better documentation now as to how to use the old version of the library and the new flipped property is incorporated across our new examples!

shiffman avatar Nov 12 '24 15:11 shiffman