JavaScript How can I detect width and height of the webcamera? detect height width

How can I detect width and height of the camera to use it on canvas and maintain the proportions??

I need to detect width and height of the camera and then use it on a canvas. In the new canvas I will show the live video with some filters. The size of the camera should be the same as the video.

The code I use to get access to the camera:

navigator.getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || naviagor.msGetUserMedia);

    var options = {video: true};
    var videoWidth, videoHeight;

    var onFail = function(e) {
      alert('Failed to get camera');
      alert(e);
    };
    var onSuccess = function(stream) {

        if(navigator.mozGetUserMedia) {
            video.mozSrcObject = stream;
        } else {
            var url = window.URL || window.webkitURL;
            video.src = url.createObjectURL(stream);
        }

        // Wait 1000 ms before starting the loop
        setTimeout(function(){

            //rest of functions ...
            //Here I need to use: videoWidth, videoHeight
            //that are obtained from the image data of the camera

        },1000);
    };

    navigator.getUserMedia(options, onSuccess, onFail);
Answer:1

There are two ways: Chrome and Firefox support the new track.getSettings():

let stream = await navigator.mediaDevices.getUserMedia({video: true});
let {width, height} = stream.getTracks()[0].getSettings();
console.log(`${width}x${height}`); // 640x480

This works regardless of whether the stream is hooked up to anything.

Alternatively, for older browsers, hook the stream up to a video element, and (importantly) wait for metadata to load, before looking at videoWidth and videoHeight:

video.srcObject = await navigator.mediaDevices.getUserMedia({video: true});
await new Promise(resolve => video.onloadedmetadata = resolve);
console.log(`${video.videoWidth}x${video.videoHeight}` // 640x480

Note that most web cams support more than one resolution. Use constraints for higher resolution:

await navigator.mediaDevices.getUserMedia({video: {width: 9999}}); // 1280x720

Here's a working fiddle.

Answer:2

I have a requirement where all the checked values in checkboxes should be displayed in a textarea. This part works perfectly fine, but the problem occurs when I uncheck the checkbox unchecked element ...

I have a requirement where all the checked values in checkboxes should be displayed in a textarea. This part works perfectly fine, but the problem occurs when I uncheck the checkbox unchecked element ...

  1. pivot table remove values heading
  2. pivot table remove values less than
  3. excel pivot table remove values
  4. pivot table remove values
  5. excel table remove values
  6. remove values from table sql
  7. remove values from table
  8. remove values header pivot table
  9. remove values from table mysql
  10. remove values from table r
  11. remove values from pivot table vba

I'm using Reactabular to create a dynamic table. I've looked everywhere in the source code but couldn't find the CSS file which is responsible for controlling the height and width of the columns. Can ...

I'm using Reactabular to create a dynamic table. I've looked everywhere in the source code but couldn't find the CSS file which is responsible for controlling the height and width of the columns. Can ...

  1. react table change width
  2. react table change column width
  3. react bootstrap table change column width

Am trying to find a better way to return a range of array values from an existing array. For an list/array of numbers, say: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] I want to select a range of 5 numbers ...

Am trying to find a better way to return a range of array values from an existing array. For an list/array of numbers, say: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] I want to select a range of 5 numbers ...

  1. find subset of array
  2. find subset of array with given sum
  3. find subset of array in java
  4. find subset of array in c
  5. find subset of array python
  6. find subset sum array
  7. find subset of array matlab
  8. finding max sum array subset
  9. finding index of the subset array

I am using React for this project. I need to read the state directly after I set it (using the callback), but when I print the state to the screen using the callback I get the values of the previous ...

I am using React for this project. I need to read the state directly after I set it (using the callback), but when I print the state to the screen using the callback I get the values of the previous ...

  1. react setstate callback example
  2. react setstate callback hooks
  3. react setstate callback arguments
  4. react setstate callback function
  5. react setstate callback async
  6. react setstate callback not called
  7. react setstate callback vs object
  8. react setstate callback state not updated
  9. react setstate callback prevstate
  10. react setstate callback before render
  11. react setstate callback previous state
  12. react setstate callback return
  13. react setstate callback doesn't work
  14. react setstate callback typescript
  15. react setstate callback functional component
  16. react setstate callback delay
  17. react setstate callback new state
  18. react setstate callback another setstate
  19. react setstate callback parameters
  20. react setstate callback called twice