champierre / tm2scratch

Connect Google Teachable Machine with Scratch
https://champierre.github.io/tm2scratch/
BSD 3-Clause "New" or "Revised" License
26 stars 27 forks source link

Incorrect Camera #38

Open QuirkyCort opened 2 years ago

QuirkyCort commented 2 years ago

When using Chrome on a computer with multiple camera, tm2scratch appears to be always using the first camera for classification, even if the on-screen video image is using a different camera.

Steps to reproduce

1) Use a computer with multiple cameras (eg. a laptop with a built-in camera and an external camera). 2) Switch the default camera in Chrome to the second camera, open up stretch3 and load the tm2scratch extension. Ensure that the video on the stage is using the second camera (...this may take some fiddling). 3) Load an image classification URL. 4) Test the image classification using the second (...on stage) camera; it won't work. 5) Test the image classification using the first camera; it'll work correctly.

This problem does not affect Firefox, and it does not affect ml2scratch either.

QuirkyCort commented 2 years ago

Did a bit more digging and can verify that the device ID for the camera used by tm2scratch is different from the device ID used for the video display on the Scratch scene. This only appears to affect Chrome.

I notice that tm2scratch is using...

video: {
    width: 360,
    height: 360
}

...while Scratch is using...

video: {
    width: {min: 480, ideal: 640},
    height: {min: 360, ideal: 480}
}

Changing tm2scratch to use the same constraints as Scratch appears to solve the problem and ensures that both video devices are the same.