eduardolundgren / tracking.js

A modern approach for Computer Vision on the web
http://trackingjs.com
Other
9.43k stars 1.44k forks source link

Camera Device Id #213

Open facetime88 opened 7 years ago

facetime88 commented 7 years ago

Hi,

I have 2 webcam camera. How do I set camera which I'd like to use for tracking? Thank you.

AnthyG commented 7 years ago

Just googled this html5 device api camera select camera.

PS.: http://stackoverflow.com/questions/21196473/how-to-select-camera-in-webapp http://stackoverflow.com/questions/18483160/which-camera-will-open-getusermedia-api-in-mobile-device-front-or-rear

koo8787 commented 7 years ago

i'm using the code. you can use this

var videoSource = "";

navigator.mediaDevices.enumerateDevices().then(function (devices) {
        for(var i = 0; i < devices.length; i ++){
            var device = devices[i];
            console.log("devices[i]",devices[i]);
            //Microsoft LifeCam Studio (045e:0772)
            //Logitech HD Pro Webcam C920 (046d:082d)
            if (device.kind === 'videoinput' && device.label === camera) {
                videoSource = device.deviceId;
            }
        };
}).then(function(){
    var constraints = {
            video: {deviceId: videoSource ? {exact: videoSource} : undefined},
    };

    navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
            try {
                element.src = window.URL.createObjectURL(stream);
            }catch (err) {
                element.src = stream;
            }
          video.onloadedmetadata = function(e) {
            video.play();
          };
        })
        .catch(function(err) {
          console.log(err.name + ": " + err.message);
        });

});
murat-aka commented 6 years ago

207