I'm working on a webapp for face detection using the user's webcam or camera. The rectangle drawn around detected faces does not align correctly on mobile. I have applied scaling to the coordinates of the rectangle to handle varying window sizes. It works without any problems on the desktop browser.
// videoX is the number of pixels on the x-axis of the video stream
var scaleX = canvas.width/videoX;
var scaleY = canvas.height/videoY;
// predictions is an array containing the coordinates of the corners of the rectangles to be drawn around the detected faces
ctx.rect(
scaleX*predictions.topLeft[0],
scaleY*predictions.topLeft[1],
scaleX*(predictions.bottomRight[0] - predictions.topLeft[0]),
scaleY*(predictions.bottomRight[1] - predictions.topLeft[1])
In portrait mode the canvas' width is too large to fit on the screen entirely. In landscape mode it does fit and the problem ceases to exist. What can I do to resolve this issue? Thank you very much for your help.