This commit is contained in:
Rhys 2025-02-03 10:40:55 -05:00
commit 4f09607579
4 changed files with 122 additions and 0 deletions

45
Count.py Normal file
View File

@ -0,0 +1,45 @@
import cv2
import numpy as np
from ultralytics import YOLO
import cvzone
device = 'cuda'
# Load the YOLO11 model
model = YOLO("yolo11m-pecan.pt")
# Open the video file (use video file or webcam, here using webcam)
cap = cv2.VideoCapture(0)
cy1=550
offset=30
idDict={}
pecanCount = 0
while True:
ret,frame = cap.read()
if not ret:
break
# Run YOLO11 tracking on the frame, persisting tracks between frames
results = model.track(frame, persist=True,classes=0,device = device)
# Check if there are any boxes in the results
if results[0].boxes is not None and results[0].boxes.id is not None:
# Get the boxes (x, y, w, h), class IDs, track IDs, and confidences
boxes = results[0].boxes.xyxy.int().cpu().tolist() # Bounding boxes
class_ids = results[0].boxes.cls.int().cpu().tolist() # Class IDs
track_ids = results[0].boxes.id.int().cpu().tolist() # Track IDs
confidences = results[0].boxes.conf.cpu().tolist() # Confidence score
for box, class_id, track_id, conf in zip(boxes, class_ids, track_ids, confidences):
x1, y1, x2, y2 = box
cy = int(y1+y2)//2
if cy<(cy1+offset) and cy>(cy1-offset) and track_id not in idDict.keys():
pecanCount += 1
idDict[track_id] = pecanCount
# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()
print(pecanCount)

12
Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM python:3.11.8
RUN apt-get update && \
apt-get install -y libgl1-mesa-glx
WORKDIR /app
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
CMD [ "python", "Count.py"]

65
requirements.txt Normal file
View File

@ -0,0 +1,65 @@
beautifulsoup4==4.12.3
certifi==2024.8.30
charset-normalizer==3.4.0
coloredlogs==15.0.1
contourpy==1.3.1
cvzone==1.6.1
cycler==0.12.1
filelock==3.16.1
filterpy==1.4.5
flatbuffers==24.3.25
fonttools==4.54.1
fsspec==2024.10.0
gdown==5.2.0
humanfriendly==10.0
idna==3.10
imageio==2.36.1
imgviz==1.7.6
Jinja2==3.1.4
kiwisolver==1.4.7
lapx==0.5.11
lazy_loader==0.4
MarkupSafe==3.0.2
matplotlib==3.9.2
mpmath==1.3.0
munkres==1.1.4
natsort==8.4.0
networkx==3.4.2
numpy==1.26.4
onnxruntime==1.20.1
opencv-python==4.10.0.84
packaging==24.2
pandas==2.2.3
pillow==11.0.0
protobuf==5.29.0
psutil==6.1.0
py-cpuinfo==9.0.0
pyparsing==3.2.0
PySocks==1.7.1
python-dateutil==2.9.0.post0
pytz==2024.2
PyYAML==6.0.2
QtPy==2.4.2
requests==2.32.3
scikit-image==0.24.0
scipy==1.14.1
seaborn==0.13.2
shapely==2.0.6
six==1.16.0
soupsieve==2.6
sympy==1.13.1
termcolor==2.5.0
tifffile==2024.9.20
torch==2.3.0
torchaudio==2.3.0
torchvision==0.18.0
tqdm==4.67.0
typing_extensions==4.12.2
tzdata==2024.2
ultralytics==8.3.29
ultralytics-thop==2.0.11
unicodedata2==16.0.0
urllib3==2.2.3

BIN
yolo11m-pecan.pt Normal file

Binary file not shown.