Skip to content

Commit

Permalink
Better support for Image & Video detection (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
AR10Dev authored Jul 5, 2024
2 parents 8cc7c5c + 922dcc3 commit 2f6b906
Show file tree
Hide file tree
Showing 9 changed files with 536 additions and 244 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: CI

on:
pull_request:
branches:
Expand All @@ -9,19 +10,21 @@ on:

jobs:
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.8]
python-version: [3.9]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip' # caching pip dependencies

- name: Install dependencies
run: |
Expand All @@ -34,10 +37,10 @@ jobs:
- name: Compile with PyInstaller
run: |
pyinstaller --onefile main.py
pyinstaller --onefile --windowed main.py
- name: Upload executable
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: main-${{ matrix.os }}
path: dist/main${{ runner.os == 'Windows' && '.exe' || '' }}
name: main-${{ matrix.os }}-${{ matrix.python-version }}
path: dist/*
Binary file removed Yolo/yolov8n.pt
Binary file not shown.
79 changes: 79 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import customtkinter as ctk
from tabs import Tabs
import os
import requests
from constants import MODEL_PATH


class AutoDetectorApp(ctk.CTk):
def __init__(self):
super().__init__()

# Download YOLO model
self.download_yolo_model()

# Set window title and disable resizing
self.title("AutoDetector v1.0.0")
self.resizable(False, False)

# Create tab view
self.tab_view = Tabs(master=self, width=800, height=600, app=self)
self.tab_view.grid(row=0, column=0, padx=20, pady=20)

# Initialize Image and Video tab elements
self.initialize_image_tab_elements()
self.initialize_video_tab_elements()

def download_yolo_model(self):
if not os.path.exists(MODEL_PATH):
os.makedirs(MODEL_PATH, exist_ok=True)
model_url = "https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt"
response = requests.get(model_url)
with open(os.path.join(MODEL_PATH, "yolov8n.pt"), "wb") as model_file:
model_file.write(response.content)

def initialize_image_tab_elements(self):
self.image_path_header = ctk.CTkLabel(
master=self.tab_view.tab("Image"), text="", font=("Arial", 20))
self.image_path_header.place(relx=0.5, rely=0.6, anchor="center")

self.image_error_path_header = ctk.CTkLabel(master=self.tab_view.tab(
"Image"), text="", font=("Arial", 20), text_color="red")
self.image_error_path_header.place(relx=0.5, rely=0.6, anchor="center")

self.image_path = ctk.CTkLabel(master=self.tab_view.tab(
"Image"), text="", font=("Arial", 15))
self.image_path.place(relx=0.5, rely=0.65, anchor="center")

self.image_detect_button = ctk.CTkButton(master=self.tab_view.tab("Image"), text="Detect now", font=("Arial", 30),
command=lambda: self.image_detection(), width=150, height=18, corner_radius=10)
self.image_detect_button.place_forget()

def initialize_video_tab_elements(self):
self.video_path_header = ctk.CTkLabel(
master=self.tab_view.tab("Video"), text="", font=("Arial", 20))
self.video_path_header.place(relx=0.5, rely=0.6, anchor="center")

self.video_error_path_header = ctk.CTkLabel(master=self.tab_view.tab(
"Video"), text="", font=("Arial", 20), text_color="red")
self.video_error_path_header.place(relx=0.5, rely=0.6, anchor="center")

self.video_path = ctk.CTkLabel(master=self.tab_view.tab(
"Video"), text="", font=("Arial", 15))
self.video_path.place(relx=0.5, rely=0.65, anchor="center")

self.video_detect_button = ctk.CTkButton(master=self.tab_view.tab("Video"), text="Detect now", font=("Arial", 30),
command=lambda: self.video_detection(), width=150, height=18, corner_radius=10)
self.video_detect_button.place_forget()

def image_detection(self):
from detection import image_detection
image_detection(self)

def video_detection(self):
from detection import video_detection
video_detection(self)

def webcam_detection(self):
from detection import webcam_detection
webcam_detection(self)
12 changes: 12 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
MODEL_PATH = "Yolo/yolov8n.pt"

classNames = ["person", "bicycle", "car", "motorbike", "aeroplane", "bus", "train", "truck", "boat",
"traffic light", "fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat",
"dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack", "umbrella",
"handbag", "tie", "suitcase", "frisbee", "skis", "snowboard", "sports ball", "kite", "baseball bat",
"baseball glove", "skateboard", "surfboard", "tennis racket", "bottle", "wine glass", "cup",
"fork", "knife", "spoon", "bowl", "banana", "apple", "sandwich", "orange", "broccoli",
"carrot", "hot dog", "pizza", "donut", "cake", "chair", "sofa", "pottedplant", "bed",
"diningtable", "toilet", "tvmonitor", "laptop", "mouse", "remote", "keyboard", "cell phone",
"microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors",
"teddy bear", "hair drier", "toothbrush"]
Loading

0 comments on commit 2f6b906

Please sign in to comment.