Skip to content

Commit 20e7efa

Browse files
committed
testing yolo26n.pt, using serial for communication now
1 parent 556459f commit 20e7efa

7 files changed

Lines changed: 72 additions & 60 deletions

File tree

File renamed without changes.

pi_serial.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import serial
2+
3+
PORT = "/dev/ttyTHS1"
4+
UART = serial.Serial(
5+
port=PORT,
6+
baudrate=9600,
7+
bytesize=serial.EIGHTBITS,
8+
parity=serial.PARITY_NONE,
9+
stopbits=serial.STOPBITS_ONE,
10+
timeout=1
11+
)

requirements.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ absl-py==2.2.2
22
asttokens==3.0.0
33
certifi==2024.12.14
44
charset-normalizer==3.4.1
5+
config==0.5.1
56
contourpy==1.3.1
67
cycler==0.12.1
78
decorator==5.2.1
@@ -11,9 +12,11 @@ executing==2.2.0
1112
filelock==3.17.0
1213
fonttools==4.55.6
1314
fsspec==2024.12.0
15+
future==1.0.0
1416
grpcio==1.71.0
1517
idna==3.10
1618
ipython==8.35.0
19+
iso8601==2.1.0
1720
jedi==0.19.2
1821
Jinja2==3.1.5
1922
joblib==1.4.2
@@ -24,7 +27,7 @@ matplotlib==3.10.0
2427
matplotlib-inline==0.1.7
2528
mpmath==1.3.0
2629
networkx==3.4.2
27-
numpy
30+
numpy==2.1.1
2831
opencv-python==4.11.0.86
2932
packaging==24.2
3033
paho-mqtt==2.1.0
@@ -47,15 +50,17 @@ requests==2.32.3
4750
scikit-learn==1.6.1
4851
scipy==1.15.1
4952
seaborn==0.13.2
53+
serial==0.0.97
54+
setuptools==80.9.0
5055
six==1.17.0
5156
stack-data==0.6.3
5257
supervision==0.25.1
5358
sympy==1.13.1
5459
tensorboard==2.19.0
5560
tensorboard-data-server==0.7.2
5661
threadpoolctl==3.6.0
57-
torch
58-
torchvision
62+
torch==2.6.0
63+
torchvision==0.21.0
5964
tqdm==4.67.1
6065
traitlets==5.14.3
6166
typing_extensions==4.12.2
@@ -64,4 +69,5 @@ ultralytics==8.3.111
6469
ultralytics-thop==2.0.14
6570
urllib3==2.3.0
6671
wcwidth==0.2.13
67-
Werkzeug==3.1.3
72+
Werkzeug==3.1.3
73+
wheel==0.45.1

vision/best.pt

-13 MB
Binary file not shown.

vision/detect.py

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,26 @@
1212
###############################################################################
1313

1414
from pathlib import Path
15+
from typing import List
1516
import supervision as sv
1617
from supervision import Point, Detections
1718
from ultralytics import YOLO
1819
import torch
1920
import argparse
2021
import cv2
2122
from os import environ
22-
from paho.mqtt.client import Client as MqttClient
23-
from paho.mqtt.client import CallbackAPIVersion
23+
# from paho.mqtt.client import Client as MqttClient
24+
# from paho.mqtt.client import CallbackAPIVersion
2425
import json
2526

27+
import pi_serial
28+
2629
DEFAULT_MODEL_PATH = Path("./model.pt")
2730
DEFAULT_WEBCAM_PORT = 0
2831
DEFAULT_CONFIDENCE_THRESHOLD = 0.5
29-
LOCAL_MQTT_BROKER_URL = environ.get("LOCAL_MQTT_BROKER_URL", None)
30-
LOCAL_MQTT_BROKER_PORT = environ.get("LOCAL_MQTT_BROKER_PORT", 1883)
31-
MQTT_VISION_DATA_TOPIC = 'vision/data'
32+
# LOCAL_MQTT_BROKER_URL = environ.get("LOCAL_MQTT_BROKER_URL", None)
33+
# LOCAL_MQTT_BROKER_PORT = environ.get("LOCAL_MQTT_BROKER_PORT", 1883)
34+
# MQTT_VISION_DATA_TOPIC = 'vision/data'
3235

3336
def main():
3437
# Parse command line arguments
@@ -77,11 +80,11 @@ def main():
7780
exit(1)
7881

7982
# Create MQTT client
80-
if LOCAL_MQTT_BROKER_URL is None:
81-
mqtt_client = None
82-
else:
83-
mqtt_client = MqttClient(CallbackAPIVersion.VERSION2)
84-
mqtt_client.connect(LOCAL_MQTT_BROKER_URL, LOCAL_MQTT_BROKER_PORT)
83+
# if LOCAL_MQTT_BROKER_URL is None:
84+
# mqtt_client = None
85+
# else:
86+
# mqtt_client = MqttClient(CallbackAPIVersion.VERSION2)
87+
# mqtt_client.connect(LOCAL_MQTT_BROKER_URL, LOCAL_MQTT_BROKER_PORT)
8588

8689
# For webcam access
8790
if args.video == DEFAULT_WEBCAM_PORT or args.video.isdigit():
@@ -141,14 +144,14 @@ def main():
141144
continue
142145

143146
# Get results from model
144-
results = model(frame, verbose=False)[0]
147+
results = model.predict(frame, verbose=False)[0]
145148
if not results:
146149
continue
147150

148151
# Pull out bounding boxes, class IDs, confidence levels, and positions
149-
boxes = results.boxes.data.cpu().numpy()
152+
boxes = results.boxes.data.cuda().numpy()
150153
class_ids = boxes[:, -1].astype(int)
151-
confidences = results.boxes.conf.cpu().numpy()
154+
confidences = results.boxes.conf.cuda().numpy()
152155
xyxy = boxes[:, :4]
153156
# Create detections object
154157
detections = Detections(
@@ -206,28 +209,30 @@ def main():
206209
# Count objects crossing the line
207210
out_to_in, in_to_out = line_counter.trigger(detections=tracked_detections)
208211

209-
if mqtt_client is not None:
210-
item_change_counts = dict()
211-
# Iterate through all detections to send a message for each one that passed the line
212-
for i, detection in enumerate(tracked_detections):
213-
# Get the label for this detection
214-
label = labels[i]
215-
if out_to_in[i]:
216-
# Detection went from out to in
217-
if label in item_change_counts:
218-
# Subtract 1 from cart
219-
item_change_counts[label] -= 1
220-
else:
221-
item_change_counts[label] = -1
222-
if in_to_out[i]:
223-
# Detection went from in to out
224-
if label in item_change_counts:
225-
# Add 1 to cart
226-
item_change_counts[label] += 1
227-
else:
228-
item_change_counts[label] = 1
229-
if len(item_change_counts) > 0:
230-
mqtt_client.publish(MQTT_VISION_DATA_TOPIC, payload=json.dumps(item_change_counts))
212+
# if mqtt_client is not None:
213+
item_change_counts = dict()
214+
# Iterate through all detections to send a message for each one that passed the line
215+
for i, detection in enumerate(tracked_detections):
216+
# Get the label for this detection
217+
label = labels[i]
218+
if out_to_in[i]:
219+
# Detection went from out to in
220+
if label in item_change_counts:
221+
# Subtract 1 from cart
222+
item_change_counts[label] -= 1
223+
else:
224+
item_change_counts[label] = -1
225+
if in_to_out[i]:
226+
# Detection went from in to out
227+
if label in item_change_counts:
228+
# Add 1 to cart
229+
item_change_counts[label] += 1
230+
else:
231+
item_change_counts[label] = 1
232+
if len(item_change_counts) > 0:
233+
data = json.dumps(item_change_counts) + '\n'
234+
pi_serial.UART.write(data.encode('utf-8'))
235+
# mqtt_client.publish(MQTT_VISION_DATA_TOPIC, payload=json.dumps(item_change_counts))
231236

232237

233238

vision/old_best.pt

18.3 MB
Binary file not shown.

weight_predict/weight_predict.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
from time import sleep
3-
import serial
3+
import pi_serial
44
from typing import List, Tuple, Dict
55
from data_classes import Item
66
import math
@@ -12,9 +12,7 @@
1212
MAX_ITEM_REMOVALS_TO_CHECK = 3
1313
THRESHOLD_WEIGHT_PROBABILITY = 30
1414

15-
ESP_SERIAL_PORT = "/dev/ttyTHS1"
16-
PI_SERIAL_PORT = "/dev/ttyUSB0"
17-
15+
# ESP_SERIAL_PORT = "/dev/ttyTHS1"
1816
class Slot:
1917

2018
_items: List[Item]
@@ -163,22 +161,14 @@ def main():
163161
mac_address_to_shelves[shelf._mac_address] = shelf
164162

165163
# Set up uart ports
166-
esp_uart_port = serial.Serial(
167-
port=ESP_SERIAL_PORT,
168-
baudrate=115200,
169-
bytesize=serial.EIGHTBITS,
170-
parity=serial.PARITY_NONE,
171-
stopbits=serial.STOPBITS_ONE,
172-
timeout=1
173-
)
174-
pi_uart_port = serial.Serial(
175-
port=PI_SERIAL_PORT,
176-
baudrate=9600,
177-
bytesize=serial.EIGHTBITS,
178-
parity=serial.PARITY_NONE,
179-
stopbits=serial.STOPBITS_ONE,
180-
timeout=1
181-
)
164+
# esp_uart_port = serial.Serial(
165+
# port=ESP_SERIAL_PORT,
166+
# baudrate=115200,
167+
# bytesize=serial.EIGHTBITS,
168+
# parity=serial.PARITY_NONE,
169+
# stopbits=serial.STOPBITS_ONE,
170+
# timeout=1
171+
# )
182172

183173
while True:
184174

@@ -217,7 +207,7 @@ def main():
217207
json_str = json.dumps(json_data) + "\n"
218208

219209
# Send it to pi
220-
pi_uart_port.write(json_str.encode('utf-8'))
210+
pi_serial.pi_uart_port.write(json_str.encode('utf-8'))
221211

222212
time_str = time.strftime("%H:%M:%S.") + f"{int((time.time() * 1000) % 1000):03d}"
223213
if item_change.quantity > 0:

0 commit comments

Comments
 (0)