Bounding box detection not consistent with changing screen resolutions

Apologies if this is not a necessarily sentis-related issue but I figured folks here might have experience with object detection applications.

I’m working on object detection and I’m facing a problem regarding cropping an image in a way that is consistent with variable screen sizes.

This is how the detection pipeline works:

Step 1: There is an ml model that takes in a RawImage and detects a bounding box on the region of interest.

Step 2: The RawImage is then cropped in order to put the content of the bounding box in a separate, cropped RawImage.

The issue is that the cropping works if the original RawImage has a ratio of 1:1. Changing the ratio (to reflect wide or mobile screens) distorts the cropped image. The issue is probably because the cropping is not accounting for the changed screen resolution.

For cropping, I’m using a shader that takes in a matrix to transform the uv of the image. The matrix is a product of a translation matrix that takes in the lower-left corner of the crop area and a scale matrix that takes in its dimensions.

I tried two ways to compute the coordinates of the crop area

One way I’m doing this is GetWorldCorners for the crop area
Then originalImageRectTransform.InverseTransformPoint for the corners so they are in the local space of the original image
Then I divide the coords by the original image’s dims to normalize

Another method is making the original image stretch over the canvas, then
GetWorldCorners() for the crop area
Then Camera.WorldToScreenPoint for every corner
Then I divide the coords by the Screen dims to normalize

Is there a solution to make the way the cropped area’s coordinates are computed adaptable to multiple screen resolutions?

Thank you