Command start the object detectiondetect run the tkinter main loopapp
Question
Please show me the code that will let me change the confidence threshold of YOLOv8 in this code. Currently using webcam as my camera feed for real-time object detection
from ultralytics import YOLO
# Load the custom YOLOv8 model
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = model(frame)
app.after(10, detect)
else:
app = tk.Tk()
app.title("YOLOv8 Inference")
clsBtn.pack()
detect()
Use the slider's value to set the confidence threshold for the YOLOv8 model.
import cv2
model = YOLO('best.pt')
# Function to update the confidence threshold based on the slider's value
def detect():
success, frame = cap.read()
photo = ImageTk.PhotoImage(image=Image.fromarray(annotated_frame))
canvas.create_image(0, 0, anchor=tk.NW, image=photo)
# Function to close the application
def close():
# Set up the Tkinter application
app = tk.Tk()
canvas = tk.Canvas(app, width=640, height=480)
canvas.pack()
# Set up the close button
clsBtn = tk.Button(app, text="Close", command=close)
app.mainloop()