Transformation between aspect ratio I am trying to measure width of an object in image. The object size is 2D object 15cm X 15cm.

When I capture a frame with resolution 1280 X 720 (16:9) I am getting that the object width is 50px.

But when I capture a frame resolution 640 X 480 (4:3) I am getting that the object width is 30px.

The distance between the object and the camera did not changed during the test.
I didn't find a transformation that can convert the width in pixels from 1280 X 720 to 640 X 480. I think that the aspect ratio is the issue here but I didn't succeed to solve it out.

How can I know that the width in pixels is both resolutions is actually the same object size?
It looks to me like the vertical dimension is the one to use for scaling:

$$\frac{50\text{ px}}{720\text{ px}} \approx \frac{30\text{ px}}{480\text{ px}}$$

There's a slight error there, but it's only a few pixels. I'm not sure if the object sizes you mentioned were intended to be precise to the nearest pixel (30 and 50 are roundish numbers).

Typically when switching between aspect ratios, the vertical FOV would remain constant while the horizontal FOV widens or narrows to match the aspect ratio.