Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustment to SSD Bounding Box Size Calculation to Account for Texture Aspect Ratio #356

Closed
keizo-yamashita opened this issue May 3, 2024 · 2 comments

Comments

@keizo-yamashita
Copy link
Contributor

keizo-yamashita commented May 3, 2024

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)

@keizo-yamashita
Copy link
Contributor Author

keizo-yamashita commented May 3, 2024

⇩Suggested MOdififcation
IMG_4749

⇩Current Code
IMG_4750

@asus4
Copy link
Owner

asus4 commented May 9, 2024

Fixed in #357. Thank you!

@asus4 asus4 closed this as completed May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants