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

How to close window in yolov5 detection #12955

Open
1 task done
tasyoooo opened this issue Apr 23, 2024 · 2 comments
Open
1 task done

How to close window in yolov5 detection #12955

tasyoooo opened this issue Apr 23, 2024 · 2 comments
Labels
question Further information is requested Stale

Comments

@tasyoooo
Copy link

Search before asking

Question

In running the detect.py in yolov5, when X button is clicked in the top right corner the window doesn't close. How to close the window without using the keyboard keys

Additional

No response

@tasyoooo tasyoooo added the question Further information is requested label Apr 23, 2024
@glenn-jocher
Copy link
Member

Hello there! 👋

For window closing issues after running detect.py where clicking the X button doesn't work, a simple workaround involves manually handling the window closure through OpenCV. You can add a conditional check after the cv2.imshow() call in the code to listen for the window close event (such as clicking the X button). Unfortunately, OpenCV doesn't directly support detecting the window close button event, so a common approach is to use cv2.waitKey() for a keyboard interrupt to close the window.

Please check if you're using a command like cv2.waitKey(0) or cv2.waitKey(1) after cv2.imshow(). If so, replacing it with a keyboard interrupt check to break the loop and then using cv2.destroyAllWindows() to close the window when a certain key is pressed (like 'q') is a typical solution. This doesn't directly solve the 'click X to close' issue but offers a straightforward way to close the window without modifying the library's source code.

Here is a quick example snippet that might be in your detect.py or a similar script:

while True:
    # Your code to display the frame
    cv2.imshow('frame', frame)

    # Break the loop and close the window when 'q' is pressed
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cv2.destroyAllWindows()

As OpenCV's imshow() doesn't inherently support a direct close window button interaction, relying on keyboard interrupts remains a practical approach.

Let me know if you have more questions or need further assistance. Happy coding! 😄

Copy link
Contributor

👋 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 ⭐

@github-actions github-actions bot added the Stale label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

2 participants