Committed Changes
This commit is contained in:
parent
e3b8320ad2
commit
990de6345d
|
@ -18,7 +18,7 @@ client = InfluxDBClient(url=INFLUX_URL, token=INFLUX_TOKEN, org=INFLUX_ORG)
|
|||
write_api = client.write_api(write_options=WriteOptions(batch_size=1))
|
||||
|
||||
# MQTT Setup
|
||||
MQTT_BROKER = "192.168.10.51"
|
||||
MQTT_BROKER = "172.20.29.125"
|
||||
MQTT_TOPIC = "fruit/classification"
|
||||
|
||||
mqtt_client = mqtt.Client()
|
||||
|
|
|
@ -8,6 +8,11 @@ import time
|
|||
from datetime import datetime
|
||||
import ssl
|
||||
import os
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from PIL import Image, ImageTk
|
||||
import threading
|
||||
|
||||
|
||||
# InfluxDB Configuration
|
||||
INFLUX_URL = "http://localhost:8086"
|
||||
|
@ -20,20 +25,75 @@ client = InfluxDBClient(url=INFLUX_URL, token=INFLUX_TOKEN, org=INFLUX_ORG)
|
|||
write_api = client.write_api(write_options=WriteOptions(batch_size=1))
|
||||
|
||||
# MQTT Setup
|
||||
MQTT_BROKER = "192.168.10.57"
|
||||
MQTT_BROKER = "192.168.8.172"
|
||||
MQTT_TOPIC = "fruit/classification"
|
||||
|
||||
def start_loading():
|
||||
for i in range(101): # 0 to 100%
|
||||
time.sleep(0.38) # 0.4s * 100 = 40 seconds
|
||||
progress_var.set(i)
|
||||
progress_bar.update_idletasks()
|
||||
root.destroy()
|
||||
|
||||
# Set up full-screen window
|
||||
root = tk.Tk()
|
||||
root.title("Starting Up")
|
||||
root.attributes('-fullscreen', True)
|
||||
|
||||
# Get screen size
|
||||
screen_width = root.winfo_screenwidth()
|
||||
screen_height = root.winfo_screenheight()
|
||||
|
||||
# Load and resize the background image
|
||||
try:
|
||||
bg_img = Image.open("comicrobodog.png") # Replace with your image
|
||||
bg_img = bg_img.resize((screen_width, screen_height), Image.ANTIALIAS)
|
||||
bg_photo = ImageTk.PhotoImage(bg_img)
|
||||
|
||||
# Set as background using a label
|
||||
bg_label = tk.Label(root, image=bg_photo)
|
||||
bg_label.place(x=0, y=0, relwidth=1, relheight=1)
|
||||
except Exception as e:
|
||||
print("Error loading background image:", e)
|
||||
root.configure(bg='black') # Fallback
|
||||
|
||||
# Overlay content frame (transparent background)
|
||||
overlay = tk.Frame(root, bg='', padx=20, pady=20)
|
||||
overlay.place(relx=0.5, rely=0.5, anchor='center')
|
||||
|
||||
# Message label
|
||||
label = tk.Label(
|
||||
overlay,
|
||||
text="Computer Vision Vignette is Starting Up",
|
||||
font=("Helvetica", 32, "bold"),
|
||||
fg="white"
|
||||
)
|
||||
label.pack(pady=10)
|
||||
|
||||
# Progress bar
|
||||
progress_var = tk.IntVar()
|
||||
progress_bar = ttk.Progressbar(
|
||||
overlay,
|
||||
maximum=100,
|
||||
variable=progress_var,
|
||||
length=800
|
||||
)
|
||||
progress_bar.pack(pady=20)
|
||||
|
||||
# Start the progress in a thread
|
||||
threading.Thread(target=start_loading, daemon=True).start()
|
||||
|
||||
# Close on ESC
|
||||
root.bind("<Escape>", lambda e: root.destroy())
|
||||
|
||||
root.mainloop()
|
||||
|
||||
|
||||
mqtt_client = mqtt.Client()
|
||||
|
||||
|
||||
# Set up TLS/SSL for MQTT connection
|
||||
|
||||
# mqtt_client.tls_set(
|
||||
# ca_certs="/Users/vel/Desktop/CvModel/mosquitto/mosquitto/certs/ca.crt", # Path to the CA certificate
|
||||
# tls_version=ssl.PROTOCOL_TLS # Specify the TLS version
|
||||
#)
|
||||
#mqtt_client.tls_insecure_set(True)
|
||||
mqtt_client.connect(MQTT_BROKER, 1883, 6000)
|
||||
mqtt_client.connect(MQTT_BROKER, 1883, 60000)
|
||||
|
||||
# Allow duplicate loading of OpenMP runtime
|
||||
os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
|
||||
|
@ -50,7 +110,7 @@ width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
|||
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
||||
|
||||
# Load the YOLO model
|
||||
model = YOLO(r"/Users/vel/Desktop/CvModel/CV_AG/runs/detect/train4/weights/best.pt") # Load custom model
|
||||
model = YOLO(r"/Users/ag_cv_gaaim/Desktop/CV_AG/runs/detect/train4/weights/best.pt") # Load custom model
|
||||
|
||||
# Define class labels
|
||||
class_labels = {
|
||||
|
@ -75,6 +135,7 @@ lemon_send_history = []
|
|||
|
||||
# Set the display window to be resizable
|
||||
cv2.namedWindow("Live Detection", cv2.WINDOW_NORMAL)
|
||||
cv2.setWindowProperty("Live Detection", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
|
||||
|
||||
# Smoothing function:
|
||||
# If the current detected label is not in smoothing_labels, clear the target's history and return the current label;
|
||||
|
@ -109,7 +170,7 @@ def get_smoothed_label(obj_id, current_label):
|
|||
# Use streaming tracking mode to maintain tracker state
|
||||
results = model.track(
|
||||
source=camera_index, # Get video stream directly from the camera
|
||||
conf=0.45,
|
||||
conf=0.3,
|
||||
tracker=yaml_path, # Use the YAML configuration file
|
||||
persist=True, # Persist tracking (do not reset)
|
||||
stream=True, # Stream processing, not frame-by-frame calling
|
||||
|
@ -117,14 +178,39 @@ results = model.track(
|
|||
device = 'mps' #'cpu'
|
||||
)
|
||||
|
||||
# Create variables to store the tracking results
|
||||
num_defective = 0
|
||||
num_good = 0
|
||||
num_notripe = 0
|
||||
last_classification = None
|
||||
|
||||
# Iterate over streaming tracking results
|
||||
for result in results:
|
||||
|
||||
frame = result.orig_img # Current frame
|
||||
|
||||
frame = cv2.flip(frame, 1)
|
||||
|
||||
detections = result.boxes # Detection box information
|
||||
|
||||
# Create bounding box for classification area
|
||||
cv2.rectangle(frame, (0, 370), (1000, 700), (0, 0, 0), -1) # Black background for text
|
||||
cv2.rectangle(frame, (0, 0), (1000, 200), (0, 0, 0), -1) # Black background for text
|
||||
cv2.rectangle(frame, (600, 200), (660, 370), (255, 255, 255), 2)
|
||||
cv2.putText(frame, "Classification Area", (560, 190), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
|
||||
# Display the number of lemons in the top left corner
|
||||
cv2.putText(frame, f"Defective: {num_defective}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2)
|
||||
cv2.putText(frame, f"Good: {num_good}", (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
|
||||
cv2.putText(frame, f"Not Ripe: {num_notripe}", (10, 90), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 100, 80), 2)
|
||||
cv2.putText(frame, f"Last Classification: {last_classification}", (10, 120), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 2)
|
||||
cv2.putText(frame, f"Total Lemons: {num_defective + num_good + num_notripe}", (10, 150), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 255), 2)
|
||||
|
||||
for box in detections:
|
||||
x1, y1, x2, y2 = map(int, box.xyxy[0]) # Detection box coordinates
|
||||
|
||||
# Adjust x-coordinates for the flipped frame
|
||||
x1, x2 = width - x2, width - x1
|
||||
|
||||
obj_id = int(box.id) if box.id is not None else -1 # Tracking ID
|
||||
class_id = int(box.cls) # Class ID
|
||||
score = box.conf # Confidence
|
||||
|
@ -160,12 +246,21 @@ for result in results:
|
|||
cv2.rectangle(frame, (x1, y1), (x2, y2), box_color, 2)
|
||||
cv2.putText(frame, display_text, (text_x, text_y),
|
||||
cv2.FONT_HERSHEY_TRIPLEX, 0.6, box_color, 2)
|
||||
cv2.rectangle(frame, (500, 0), (1000, 170), (0, 0, 0), -1) # Black background for text
|
||||
|
||||
if x1 > 750 and x1 < 850 and y2 < 410 and y1 > 190 and obj_id not in lemon_send_history:
|
||||
if x1 > 600 and x1 < 660 and y2 < 410 and y1 > 190 and obj_id not in lemon_send_history:
|
||||
if final_label in ["DefectiveLemon", "NotRipeLemon", "GoodLemon"]:
|
||||
mqtt_message = f"lemon_classification classification=\"{final_label}\" {int(time.time()*1e9)}"
|
||||
lemon_send_history.append(obj_id)
|
||||
mqtt_client.publish(MQTT_TOPIC, mqtt_message)
|
||||
# Update Tracking Variables
|
||||
if final_label == "DefectiveLemon":
|
||||
num_defective += 1
|
||||
elif final_label == "GoodLemon":
|
||||
num_good += 1
|
||||
elif final_label == "NotRipeLemon":
|
||||
num_notripe += 1
|
||||
last_classification = final_label
|
||||
else:
|
||||
# For other classes, display the current detection result directly and clear history (if exists)
|
||||
if obj_id in lemon_history:
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
source /Users/ag_cv_gaaim/Desktop/CV_AG/cvag/bin/activate
|
||||
python3 /Users/ag_cv_gaaim/Desktop/CV_AG/Test_Track_updated.py
|
Binary file not shown.
After Width: | Height: | Size: 2.6 MiB |
|
@ -0,0 +1,65 @@
|
|||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from PIL import Image, ImageTk
|
||||
import time
|
||||
import threading
|
||||
|
||||
def start_loading():
|
||||
for i in range(101): # 0 to 100%
|
||||
time.sleep(0.4) # 0.4s * 100 = 40 seconds
|
||||
progress_var.set(i)
|
||||
progress_bar.update_idletasks()
|
||||
root.destroy()
|
||||
|
||||
# Set up full-screen window
|
||||
root = tk.Tk()
|
||||
root.title("Starting Up")
|
||||
root.attributes('-fullscreen', True)
|
||||
|
||||
# Get screen size
|
||||
screen_width = root.winfo_screenwidth()
|
||||
screen_height = root.winfo_screenheight()
|
||||
|
||||
# Load and resize the background image
|
||||
try:
|
||||
bg_img = Image.open("comicrobodog.png") # Replace with your image
|
||||
bg_img = bg_img.resize((screen_width, screen_height), Image.ANTIALIAS)
|
||||
bg_photo = ImageTk.PhotoImage(bg_img)
|
||||
|
||||
# Set as background using a label
|
||||
bg_label = tk.Label(root, image=bg_photo)
|
||||
bg_label.place(x=0, y=0, relwidth=1, relheight=1)
|
||||
except Exception as e:
|
||||
print("Error loading background image:", e)
|
||||
root.configure(bg='black') # Fallback
|
||||
|
||||
# Overlay content frame (transparent background)
|
||||
overlay = tk.Frame(root, bg='', padx=20, pady=20)
|
||||
overlay.place(relx=0.5, rely=0.5, anchor='center')
|
||||
|
||||
# Message label
|
||||
label = tk.Label(
|
||||
overlay,
|
||||
text="Computer Vision Vignette is Starting Up",
|
||||
font=("Helvetica", 32, "bold"),
|
||||
fg="white"
|
||||
)
|
||||
label.pack(pady=10)
|
||||
|
||||
# Progress bar
|
||||
progress_var = tk.IntVar()
|
||||
progress_bar = ttk.Progressbar(
|
||||
overlay,
|
||||
maximum=100,
|
||||
variable=progress_var,
|
||||
length=800
|
||||
)
|
||||
progress_bar.pack(pady=20)
|
||||
|
||||
# Start the progress in a thread
|
||||
threading.Thread(target=start_loading, daemon=True).start()
|
||||
|
||||
# Close on ESC
|
||||
root.bind("<Escape>", lambda e: root.destroy())
|
||||
|
||||
root.mainloop()
|
Loading…
Reference in New Issue