-
-
Notifications
You must be signed in to change notification settings - Fork 16k
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 add a button inside the video stream of yolov5. #12950
Comments
Hello! 😊 Adding a UI element like a button requires integrating YOLOv5's output with a graphical user interface (GUI) library, as YOLOv5 itself doesn't handle GUI components directly. For a simple implementation with Python, you can consider using Tkinter alongside OpenCV. However, this involves modifying the code to run detections in a separate thread or process, updating the GUI with the video feed, and then handling the button event to terminate the window. Here's a very simplified outline of what this could look like: import cv2
from tkinter import *
from threading import Thread
# Function to handle detections and display video
def video_stream():
cap = cv2.VideoCapture(0) # Webcam source
while True:
ret, frame = cap.read()
if ret:
# Your YOLOv5 detection code would go here. For simplicity, we're just displaying the frame.
cv2.imshow('YOLOv5 Detection', frame)
if cv2.waitKey(1) & 0xFF == ord('q'): # Modify as necessary based on your GUI event
break
cap.release()
cv2.destroyAllWindows()
# Function to start video stream in a thread
def start_stream():
Thread(target=video_stream).start()
# Function to destroy the window - you'd call this with your button
def destroy_window():
cv2.destroyAllWindows() # Close the CV2 window
root.destroy() # Close the tkinter window
# Setting up a simple tkinter window
root = Tk()
root.title("YOLOv5 GUI")
start_btn = Button(root, text="Start YOLOv5 Stream", command=start_stream)
start_btn.pack()
close_btn = Button(root, text="Close", command=destroy_window)
close_btn.pack()
root.mainloop() Do note, this is a very basic implementation and may need significant adjustments based on your specific requirements. Integrating real-time detection with GUI libraries can be complex and might require a more in-depth approach. Happy coding! 🚀 |
👋 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 ⭐ |
Search before asking
Question
I'm using webcam as the source, what modification in detect.py i can add to add a button that has a function to destroy the window
Additional
No response
The text was updated successfully, but these errors were encountered: