yolov5-mouse-control
A sample yolov5 mouse control with an Arduino Leonardo & USB Host shield 2.0
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.6%) to scientific vocabulary
Repository
A sample yolov5 mouse control with an Arduino Leonardo & USB Host shield 2.0
Basic Info
- Host: GitHub
- Owner: iwebbo
- License: agpl-3.0
- Language: Python
- Default Branch: main
- Size: 354 KB
Statistics
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
Automated Mouse Control with YOLOv5 and Arduino
This project uses a custom YOLOv5 model to detect objects on the screen and control the mouse position based on the detected objects. It also sends the coordinates of the detected objects to an Arduino via serial communication.
📌 Technologies
📌 Prerequisites
🖥 Hardware:
- A computer capable of capturing the screen in real-time.
- An Arduino connected via a serial port (e.g., Arduino Uno).
- A USB cable to connect the computer and the Arduino.
🛠 Software:
- Python 3.x installed on your machine.
- Required Python libraries (see Installation).
- A custom YOLOv5 model in
.ptformat (e.g.,best_fornite.pt).
🔧 Installation
Install the required Python libraries:
sh
pip install opencv-python torch pyautogui numpy pillow ultralytics
Connect your Arduino and note the serial port being used (e.g., COM10 on Windows or /dev/ttyUSBx on Linux).
Download or train your own YOLOv5 model and place it in the project directory.
⚙️ Configuration
- Arduino Serial Port: Modify the
portvariable in the script to match your Arduino's serial port. - YOLOv5 Model: Ensure that the model file specified in
load_yolov5_model()matches your custom model path (default:best_fornite.pt).
🚀 Usage
Run the Python script:
sh
python mousecontrol_for_com_arduino_image_detect.py
The program will capture the screen in real-time, detect objects, and move the mouse accordingly.
Make sure to update these values according to your setup:
```python port = 'COM10' # Replace with the correct COM port (COMx on Windows, /dev/ttyUSBx on Linux)
baudrate = 9600 # Adjust based on your Arduino input. Modify if latency issues occur to avoid overloading the Arduino.
def loadyolov5model(modelpath='bestfornite.pt'): # Replace with your model. # Example: We trained on a custom Fortnite dataset, using 326headbody.pt from the repository. ```
✨ Features
✅ Real-time Object Detection: Uses YOLOv5 to identify objects on the screen.
✅ Mouse Control: Moves the mouse to the center of the detected object.
✅ Arduino Communication: Sends detected object coordinates via the serial port.
⚠️ Limitations
- Detection performance depends on the YOLOv5 model and screen capture speed.
- The project should be migrated to YOLOv8 & YOLOv11 for improved tracking (GitHub Link).
- Ensure that the in-game resolution matches the resolution configured in the script (default:
1920x1080).
🛠 Troubleshooting
🔹 Mouse movement issues: Verify that the model is working correctly. The script runs in verbose mode, so logs should be available.
🔹 Arduino not responding: Ensure the Arduino is connected to the correct serial port and the baudrate matches.
🔹 Firmware issues: Check that the firmware is properly uploaded to your Arduino.
🔹 Resolution mismatch: Ensure the mapped coordinates align with your screen resolution.
💡 Feel free to contribute and improve this project! 🚀
French Documentation
Contrôle de Souris Automatisé avec YOLOv5 et Arduino
Ce projet utilise un modèle YOLOv5 personnalisé pour détecter des objets à l'écran et contrôler la position de la souris en fonction des objets détectés. Il envoie également les coordonnées des objets détectés à un Arduino via une communication série.
Prérequis
Matériel :
- Un ordinateur capable de capturer l'écran en temps réel.
- Un Arduino connecté via un port série (par exemple, Arduino Uno).
- Un câble USB pour la connexion entre l'ordinateur et l'Arduino.
Logiciel :
- Python 3.x installé sur votre machine.
- Bibliothèques Python nécessaires (voir Installation).
- Un modèle YOLOv5 personnalisé au format
.pt(par exemple,best_fornite.pt).
Installation
Installez les bibliothèques Python requises :
bash pip install opencv-python torch pyautogui numpy pillow ultralyticsConnectez votre Arduino et notez le port série utilisé (par exemple,
COM10sous Windows ou/dev/ttyUSBxsous Linux).Téléchargez ou entraînez votre propre modèle YOLOv5, puis placez-le dans le répertoire du projet.
Configuration
- Port série Arduino : Modifiez la variable
portdans le script pour correspondre au port série de votre Arduino. - Modèle YOLOv5 : Assurez-vous que le fichier modèle spécifié dans
load_yolov5_model()correspond au chemin de votre modèle personnalisé (par défaut :best_fornite.pt).
Utilisation
Lancez le script Python :
bash python mousecontrol_for_com_arduino_image_detect.pyLe programme capturera l'écran en temps réel, détectera des objets, et déplacera la souris en conséquence.
Ne pas oublier de modifier ces valeurs en fonction de vos entrées computer.
port = 'COM10' # Remplacez par le port COM correct (COMx sur Windows, /dev/ttyUSBx sur Linux)
baudrate = 9600 # A modifier en fonction de votre input arduino, à modifier également si des latences sont perçus, afin de ne pas surchager l'arduino.
def loadyolov5model(modelpath='bestfornite.pt'): # Modifier par votre modele, dans ce cas présent, nous avons entrainés depuis un dataset custom Fortnite, au sein du Repo utiliser 326headbody.pt
Fonctionnalités
- Détection d'objets en temps réel : Utilise YOLOv5 pour identifier les objets à l'écran.
- Contrôle de la souris : Déplace la souris vers le centre de l'objet détecté.
- Communication avec Arduino : Envoie les coordonnées des objets détectés via le port série.
Limitations
- La détection est limitée par les performances du modèle YOLOv5 et la vitesse de capture de l'écran.
- Le projet devrait être migré en Yolov8 & Yolov11 (https://github.com/iwebbo/yolov8-tracking-fps)
- Assurez-vous que la résolution de l'écran utilisée dans le jeu correspond à celle configurée dans le script (par défaut : 1920x1080).
Dépannage
- Si la souris ne bouge pas correctement, vérifiez votre modèle & le prompt est resté en verbose, vous aurez donc accès aux logs.
- Assurez-vous que l'Arduino est connecté au bon port série et que le baudrate correspond.
- Assurez-vous que le firmware est correctement chargé sur votre arduino.
- Assusez-vous que votre résolution soit coordonnnée : # Mapper ces coordonnées à la résolution de l'écran
Owner
- Login: iwebbo
- Kind: user
- Repositories: 1
- Profile: https://github.com/iwebbo
Citation (CITATION.cff)
cff-version: 1.2.0
preferred-citation:
type: software
message: If you use YOLOv5, please cite it as below.
authors:
- family-names: Jocher
given-names: Glenn
orcid: "https://orcid.org/0000-0001-5950-6979"
title: "YOLOv5 by Ultralytics"
version: 7.0
doi: 10.5281/zenodo.3908559
date-released: 2020-5-29
license: AGPL-3.0
url: "https://github.com/ultralytics/yolov5"
GitHub Events
Total
- Watch event: 1
- Push event: 7
- Create event: 2
Last Year
- Watch event: 1
- Push event: 7
- Create event: 2
Dependencies
- pytorch/pytorch 2.0.0-cuda11.7-cudnn8-runtime build
- gcr.io/google-appengine/python latest build
- matplotlib >=3.3.0
- numpy >=1.22.2
- opencv-python >=4.6.0
- pandas >=1.1.4
- pillow >=7.1.2
- psutil *
- py-cpuinfo *
- pyyaml >=5.3.1
- requests >=2.23.0
- scipy >=1.4.1
- seaborn >=0.11.0
- thop >=0.1.1
- torch >=1.8.0
- torchvision >=0.9.0
- tqdm >=4.64.0
- ultralytics >=8.1.47
- PyYAML >=5.3.1
- gitpython >=3.1.30
- matplotlib >=3.3
- numpy >=1.23.5
- opencv-python >=4.1.1
- pandas >=1.1.4
- pillow >=10.3.0
- psutil *
- requests >=2.32.2
- scipy >=1.4.1
- seaborn >=0.11.0
- setuptools >=70.0.0
- thop >=0.1.1
- torchvision >=0.9.0
- tqdm >=4.66.3
- Flask ==2.3.2
- gunicorn ==22.0.0
- pip ==23.3
- werkzeug >=3.0.1
- zipp >=3.19.1