Repository: opencv
Issue: [OpenCV.js] Error when creating VideoCapture : wrong video size.
Labels: category: javascript (js)

<!--
If you have a question rather than reporting a bug please go to https://forum.opencv.org where you get much faster responses.
If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).

This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.
-->

##### System information (version)
<!-- Example
- OpenCV => 4.2
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2017
-->

- OpenCV => 4.5.2
- Operating System / Platform => Chrome on Android
- Compiler => :grey_question:

##### Detailed description

Hi ! I'm trying to use OpenCV.js on mobile phones for image tracking. For now I follow the tutorials to get the basics. I've set a \<video\> tag that starts streaming a camera on the mobile phone, then I create a new VideoCapture to capture the stream. The problem is that VideoCapture seams to check the _video.height_ and _video.width_ properties that are not initialized after the stream starts. Is it an error in the tutorial or did I miss something ?

Link to the tutorial : [https://docs.opencv.org/4.5.2/dd/d00/tutorial_js_video_display.html](https://docs.opencv.org/4.5.2/dd/d00/tutorial_js_video_display.html)

##### Steps to reproduce

What I did is to wait for the first frame to be rendered with _setTimeout_ because its size is (0, 0) and then I change _video.height_ and _video.width_ by hand before creating VideoCapture :
```js
// start video stream

setTimeout(function () {
    video.height = video.videoHeight;
    video.width = video.videoWidth;
    cap = new cv.VideoCapture(video);

    // call to process function here
}, 50);
```

##### Issue submission checklist

 - [X] I report the issue, it's not a question
   <!--
   OpenCV team works with forum.opencv.org, Stack Overflow and other communities
   to discuss problems. Tickets with question without real issue statement will be
   closed.
   -->
 - [X] I checked the problem with documentation, FAQ, open issues,
       forum.opencv.org, Stack Overflow, etc and have not found solution
   <!--
   Places to check:
   * OpenCV documentation: https://docs.opencv.org
   * FAQ page: https://github.com/opencv/opencv/wiki/FAQ
   * OpenCV forum: https://forum.opencv.org
   * OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
   * Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
   -->
 - [X] I updated to latest OpenCV version and the issue is still there
   <!--
   master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
   OpenCV team supports only latest release for each branch.
   The ticket is closed, if the problem is not reproduced with modern version.
   -->
 - [x] There is reproducer code and related data files: videos, images, onnx, etc
   <!--
   The best reproducer -- test case for OpenCV that we can add to the library.
   Recommendations for media files and binary files:
   * Try to reproduce the issue with images and videos in opencv_extra repository
     to reduce attachment size
   * Use PNG for images, if you report some CV related bug, but not image reader
     issue
   * Attach the image as archive to the ticket, if you report some reader issue.
     Image hosting services compress images and it breaks the repro code.
   * Provide ONNX file for some public model or ONNX file with with random weights,
     if you report ONNX parsing or handling issue. Architecture details diagram
     from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
   -->