Yolov5 shift issue

Hello everyone ,
I used two yolov5 models. My first model detects the tray. In my second model, it finds food types.

The size of the first model was 416, then I cropped it. I sent it to the second model. The size of my second model is 224.

The reason for the shift problem is crop . It detective the food in the cropped image. Draws the result for the original image. It should change according to the center of the tray. I understand the problem, but I didn’t understand how to change it.

I created a table in debug mode. I wrote the values.
Do I need to increase xPos and yPos values when drawing? There are only location values in the MultiBoxerTracker file. bottom, left right, top. I’m so confused. I would love any help,advice. Thanks a lot.

Hello @Laura1

Thank you for using TensorFlow,

In the flow of the two models, the output of first model will be tray’s bbox (6, 389, 968,1350), so the width of tray on original image is 962, and height is 961, After this the image is cropped to 224x224 to input through second model,
The detected object bbox is (54,79,48,25).
so transformation ideally goes like this,
scaled_x = 962/224 = 4.2
scaled_y = 961/224 = 4.2

so detected object scaled width and height will be (48x4.2, 25x4.2)= (206,107)
the coordinates need to be translated so that we can draw the bbox on original image

object_x1_final = tray_x1_orig + object_x_rel_tray = 6 + 544.2 = 237.9
object_y1_final = tray_y1_orig + object_y_rel_tray = 389 + 79
4.2 = 727.9

we need to xpos and ypos from second model with respect to the ration of original tray size and 224x224.
In the Multitracker2.java or the file where final drawing on image happen we need to implement this change to get bbox.
Thank you