ultralytics / yolo-flutter-app

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

Need help with stopping and resuming object detection in ultriclitics_yolo model in Flutter #43

Closed nikhilgarala-tecblic closed 3 months ago

nikhilgarala-tecblic commented 4 months ago

Hello Team,

I am trying to achieve a scenario where I can stop the prediction of the ultriclitics_yolo model when an object is detected, and then resume it later. Currently, I am using controller.pushPredirection() to attempt to stop the prediction, but it doesn't seem to work as expected. After calling this method, the prediction continues.

My goal is to display some images when an object is detected, and during this time, I want to halt the ultriclitics_yolo model's detection process. When the user interacts with the displayed images (e.g., by clicking on a close icon), I would like to resume the prediction.

Could you please guide me on how to achieve this in Flutter using ultralitics?

pderrenger commented 4 months ago

Hello,

Thank you for reaching out with your question! It sounds like an interesting use case for the Ultralytics YOLO model in a Flutter application.

To achieve the functionality of stopping and resuming object detection, you can manage the state of the detection process using a boolean flag and control the prediction loop accordingly. Here's a conceptual approach to help you get started:

  1. Define a Boolean Flag: Create a boolean flag to control the prediction state.
  2. Modify the Prediction Loop: Use this flag to conditionally run the prediction loop.
  3. Control the Flag: Update the flag based on user interactions to stop and resume predictions.

Here's a simplified example to illustrate this:

bool isDetecting = true; // Flag to control detection

void startDetection() async {
  while (isDetecting) {
    // Perform prediction
    var result = await controller.predict();

    // Check if an object is detected
    if (result.isNotEmpty) {
      // Stop detection
      isDetecting = false;
      // Display images or perform other actions
      showImages();
    }
  }
}

void showImages() {
  // Display images to the user
  // Add a close icon or button for user interaction
}

void onCloseIconClicked() {
  // Resume detection when the user interacts with the close icon
  isDetecting = true;
  startDetection();
}

In this example:

Please ensure you are using the latest version of the Ultralytics YOLO model and Flutter packages to avoid any compatibility issues. If you encounter any further issues, feel free to update this thread with more details.

I hope this helps! If you have any more questions or need further assistance, please let me know.

nikhilgarala-tecblic commented 3 months ago

Thank you for the answer !

glenn-jocher commented 3 months ago

@nikhilgarala-tecblic hello,

You're welcome! 😊 I'm glad I could help. If you encounter any further issues or have additional questions, please don't hesitate to ask.

If you believe there might be a bug or unexpected behavior, I recommend verifying that the issue persists with the latest versions of the Ultralytics YOLO model and any related packages. Keeping everything up-to-date can often resolve unexpected issues.

Feel free to share any more details or specific challenges you face, and I'll be happy to assist further. The Ultralytics community and team are here to support you!