-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fix: video crops when webcam resolution is not 480p #5
base: main
Are you sure you want to change the base?
Conversation
…hing not rendering
@parth-agrawal Thank you for bringing the issue to our attention and for the contribution. At the moment we'd rather the demo keep a constant pixel resolution so that it works well with our content management system and we can ensure layouts on a variety of device sizes. I pushed a separate fix to the repo which handles differing webcam sizes while maintaining container sizes for layout (would be great if you could test that :)). However, I'm sure other users will want the scaling containers you show in your PR so it would be great if you instead moved those to separate html and js files for a separate "scaling" demo (maybe update the README while your at it). At which point you can request a review from me and I'd be happy to merge that demo into the main repo. |
Description
If the demo receives webcam video of a resolution different from 480p, the demo does not scale the webcam video or canvas correctly. This appears on both the Roboflow homepage and the test page in this repository. This fix changes
script.js
so that canvas height is fixed to 480 pixels, but canvas width is scaled to match the aspect ratio of incoming video.Loom Explainer
https://www.loom.com/share/53c58cccee104e2d951244d0ddda6032
Motivation
I encountered this bug because I was on a Google Meet call with a colleague while testing the demo. I determined that Google Meet was requesting 720p video from the webcam. The Roboflow demo appears to tap the same video source, so it also received 720p video. It handled this incorrectly; the video cropped to the top left corner of the video. Inference was also performed incorrectly as a result of this.
To Reproduce
Fix
Summary of changes
webcamInference()
videoAspectRatio
as width/heightgetCoordinates()
calculation outside of video render loopgetCoordinates()
calculation of canvas width and heightgetCoordinates()
videoAspectRatio
videoAspectRatio
sWidth
to the incoming true webcam video width, which fixes the scalingRatio calculationcanvasRatio
andimageRatio
are not necessary given that we know the true webcam video dimensionsgetBase64Image()
imageInference()
To Test the Fix
Type of change