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

Calling currentImg = video.get(); and afterwards mobilenet.predict(currentImg, gotResults); gives error. #202

Closed
CreativeCode opened this issue Aug 16, 2018 · 1 comment

Comments

@CreativeCode
Copy link

CreativeCode commented Aug 16, 2018

Dear community,
I have been inspired by Shiffman's videos about Image Classification and Video Classification. Consequently, I tried to combine working with video and with images. I tried to take a snapshot from the webcam and submit this snapshot for classification. The code is below. Unfortunately, I get an error (see screenshot).

I am not sure whether this is an issue or a mistake on my side.

Many thanks for your help and for the great library!
Hanna

Code:

let video;
let label = '';
let captureBtn; 
let useButton;
let currentImg;
let retake = true;


function classify() {
    mobilenet.predict(currentImg, gotResults);
}

function modelReady() {
    console.log('Model is raedy!!!');
}

function gotResults(error, results) {
    if (error) {
        console.error(error);
    } else {
        console.log(results);
        label = results[0].className;
        let prob = results[0].probability;
    }
}

function takesnap() {
    currentImg = video.get(); 
    if (retake) {
        captureBtn.html('retake');
        useBtn.show();
    } 
    else {
        captureBtn.html('snap!');
        useBtn.hide();
    }
    retake = !retake;

}

function setup() {
    createCanvas(320, 240);
    video = createCapture(VIDEO);
    video.size(320, 240);
    video.hide();
    currentImg = createImage(320,240);
    mobilenet = ml5.imageClassifier('MobileNet', modelReady);

    background(0);

    captureBtn = createButton('Snap');
    captureBtn.mousePressed(takesnap);
    useBtn = createButton('Use this picture');
    useBtn.mousePressed(classify);
    useBtn.hide();

}

function draw() {
    if (retake) {
        var frame = video.get();
        image(frame,0,0);
    } 
}

screen shot 2018-08-16 at 18 52 14

@cvalenzuela
Copy link
Member

You are getting the current image using

video.get()

That will return a p5.Image. The classifier expects a DOM image or DOM Video

See this: ml5js/ml5-examples#7

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