ultralytics / yolo-flutter-app

A Flutter plugin for Ultralytics YOLO computer vision models
https://ultralytics.com
GNU Affero General Public License v3.0
36 stars 14 forks source link

Currently the results from file recognition are scaled to the device's screen size #15

Closed x2031 closed 1 month ago

x2031 commented 2 months ago

Currently, the result of file recognition is scaled according to the screen size of the device, is it possible to add a new type in YoloModel to control whether or not scaling is enabled?

float x = obj[0] * widthDp;
float y = obj[1] * newHeight;
float width = obj[2] * widthDp;
float height = obj[3] * newHeight;
float confidence = obj[4];
int index = (int) obj[5];

Something like this.

public abstract class YoloModel {
    public final ArrayList<String> labels = new ArrayList<>();
    public String task;
    public String format;
    public boolean isLive;//Whether to enable auto zoom
}
pderrenger commented 2 months ago

Hello! 😊

It's great that you're diving into customization! To control scaling in YoloModel, adding a flag like isLive for auto zoom is indeed a good approach. Your suggestion looks like a solid starting point. Here's a simplified way to integrate this:

  1. In your YoloModel class, introduce a boolean field to enable or disable scaling. You're already on the right track with public boolean isLive;.

  2. Adjust your scaling logic based on this flag. For instance:

float scaleFactor = isLive ? 1.0f : getScaleFactor(); // Define getScaleFactor() as needed
float x = obj[0] * widthDp * scaleFactor;
float y = obj[1] * newHeight * scaleFactor;
float width = obj[2] * widthDp * scaleFactor;
float height = obj[3] * newHeight * scaleFactor;
  1. Make sure to provide a mechanism (either a setter method or direct public access) to toggle isLive.

This way, you maintain control over the scaling behavior and can toggle it based on your needs. Remember to adapt the getScaleFactor() method to match your specific requirements for non-live scenarios.

Happy coding! If you need more detailed guidance, the Ultralytics Docs at https://docs.ultralytics.com could be handy. Keep exploring!

x2031 commented 2 months ago

你好!😊

您正在潜心进行定制,这真是太好了!为了控制YoloModel中的缩放,添加一个像自动缩放这样的标志确实是一个好方法。您的建议看起来是一个坚实的起点。下面是集成此功能的简化方法:isLive

  1. 在 YoloModel 类中,引入一个布尔字段来启用或禁用缩放。您已经走在正确的轨道上。public boolean isLive;
  2. 根据此标志调整缩放逻辑。例如:
float scaleFactor = isLive ? 1.0f : getScaleFactor(); // Define getScaleFactor() as needed
float x = obj[0] * widthDp * scaleFactor;
float y = obj[1] * newHeight * scaleFactor;
float width = obj[2] * widthDp * scaleFactor;
float height = obj[3] * newHeight * scaleFactor;
  1. 确保提供一种机制(setter 方法或直接公共访问)来切换 。isLive

这样,您就可以保持对缩放行为的控制,并可以根据需要进行切换。请记住调整该方法,以满足你对非实时方案的特定要求。getScaleFactor()

祝您编码愉快!如果您需要更详细的指导,https://docs.ultralytics.com 的 Ultralytics Docs 可能会很方便。继续探索!

I have implemented it, is it possible to submit pr

pderrenger commented 2 months ago

Hello! 😊

Absolutely fantastic that you've implemented the feature! We're always excited to see community contributions. Yes, you're welcome to submit a PR. Please make sure your changes align with the project's standards and include a brief description of your implementation and how it enhances functionality or user experience.

Looking forward to your contribution!

Happy coding!

x2031 commented 2 months ago

Hello! 😊

Absolutely fantastic that you've implemented the feature! We're always excited to see community contributions. Yes, you're welcome to submit a PR. Please make sure your changes align with the project's standards and include a brief description of your implementation and how it enhances functionality or user experience.

Looking forward to your contribution!

Happy coding!

I'll submit it later.

pderrenger commented 2 months ago

Fantastic! 😊 We're looking forward to reviewing your PR. If you have any questions or need guidance, feel free to ask.

Happy coding!

github-actions[bot] commented 1 month ago

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐