Adjustment to SSD Bounding Box Size Calculation to Account for Texture Aspect Ratio
kaku-panda opened this issue · comments
Hello,
Firstly, I would like to express my gratitude for developing such a useful package that greatly enhances the implementation of object detection in Unity. It has been incredibly helpful.
I have identified an issue where the bounding boxes become disproportionately wide when the texture dimensions do not match the display aspect ratio. This seems to stem from not accounting for the texture's aspect ratio in the bounding box size calculation in the Invoke method.
Proposed Change:
Include the texture's aspect ratio in the bounding box size calculations to ensure that bounding boxes are scaled and positioned accurately relative to the objects they are meant to represent.
↓ Current Code (SsdSample)
Vector2 size = (frameContainer.transform as RectTransform).rect.size;
for (int i = 0; i < 10; i++)
{
SetFrame(frames[i], results[i], size);
}
↓Suggested Modification (SsdSample)
Vector2 ratio;
if (texture.width >= texture.height)
{
ratio = new Vector2(1.0f, (float)texture.height / (float)texture.width);
}
else
{
ratio = new Vector2((float)texture.width / (float)texture.height, 1.0f);
}
for (int i = 0; i < 10; i++)
{
SetFrame(frames[i], results[i], size * ratio);
}
This modification will help to correct the aspect ratio of bounding boxes, making them more accurate and visually representative of the actual objects detected.
Thank you once again for your incredible work.
[PR Link] : #357 (comment)
Fixed in #357. Thank you!