# Background Scaling Issue on Mobile

**URL:** <https://forum.babylonjs.com/t/background-scaling-issue-on-mobile/38281>\
**Category:** Questions\
**Created:** [February 16, 2023, 5:25pm UTC](https://forum.babylonjs.com/t/background-scaling-issue-on-mobile/38281 "2023-02-16T17:25:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rdurnin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rdurnin/32/11381_2.png) [@rdurnin](https://forum.babylonjs.com/u/rdurnin)\
**Post date:** [February 16, 2023, 5:25pm UTC](https://forum.babylonjs.com/t/background-scaling-issue-on-mobile/38281/1 "2023-02-16T17:25:12Z")

</div>

Hello, and thanks for any help you might lend. I am working with a background layer to capture a webcam into a fullscreen texture, and found some useful code for resizing in another thread (@bghgary [FullScreenLayer video; dynamically change the aspect ratio - #2 by carolhmj](https://forum.babylonjs.com/t/fullscreenlayer-video-dynamically-change-the-aspect-ratio/25394/2)). The webcam image is being sent through a facemesh camera to allow me to track face landmarks in the image, and is showing some distortion on mobile. It is possible that the error is being introduced by scaling the texture which facemesh is using to create the landmarks, although the desktop version doesn’t show the issue.

I have tried pushing content through the scene to see if the distortion is in the 3d render, but it is only in the landmark positions (and generated mesh).

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#YI2KQD%2316)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

r

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 16, 2023, 5:30pm UTC](https://forum.babylonjs.com/t/background-scaling-issue-on-mobile/38281/2 "2023-02-16T17:30:42Z")

</div>

I see an offset for my desktop webcam also, so this is not limited to mobile.

---

<div class="post-metadata">

**Author:** ![rdurnin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rdurnin/32/11381_2.png) [@rdurnin](https://forum.babylonjs.com/u/rdurnin)\
**Post date:** [February 16, 2023, 5:34pm UTC](https://forum.babylonjs.com/t/background-scaling-issue-on-mobile/38281/3 "2023-02-16T17:34:43Z")

</div>

The offset, I believe, is the result of the difference in angle between the scene and my desktop camera. I am looking at how to correct it using the face normals (and perhaps intraocular distance). On mobile (portrait) the facemesh generated model looks distorted in y, although the tracking objects appear to have the right proportions.

It is also possible I have been looking at this too long.

Thanks again.

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [February 16, 2023, 6:00pm UTC](https://forum.babylonjs.com/t/background-scaling-issue-on-mobile/38281/4 "2023-02-16T18:00:17Z")

</div>

I’m guessing you’ve already read this, but it seems to explain how the transform works.

[Face Mesh | mediapipe (google.github.io)](https://google.github.io/mediapipe/solutions/face_mesh.html#face-transform-module)

It looks like we need a [Weak perspective projection](https://en.wikipedia.org/wiki/3D_projection#Weak_perspective_projection), which I’m not sure how to do in Babylon.js, but it should be possible.

---

<div class="post-metadata">

**Author:** ![rdurnin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rdurnin/32/11381_2.png) [@rdurnin](https://forum.babylonjs.com/u/rdurnin)\
**Post date:** [February 17, 2023, 10:21am UTC](https://forum.babylonjs.com/t/background-scaling-issue-on-mobile/38281/5 "2023-02-17T10:21:49Z")

</div>

Thanks, and I should be able derive the perspective camera using the webcam focal distance, but will need to correct the camera pose to account for the location of the webcam. There are some tools included within mediapipe/camera\_utils which are for that purpose.

I’ll update the demo when I have something.  
r

---

<div class="post-metadata">

**Author:** ![rdurnin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rdurnin/32/11381_2.png) [@rdurnin](https://forum.babylonjs.com/u/rdurnin)\
**Post date:** [February 17, 2023, 11:55am UTC](https://forum.babylonjs.com/t/background-scaling-issue-on-mobile/38281/6 "2023-02-17T11:55:42Z")

</div>

The pose transform matrix is included with the geometry in face mesh, and can be used to transform the vertices into correct 3d positions. I will update the demo in the other thread.

Thanks for the insight,  
r
