Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 45 additions & 9 deletions src/computer_vision/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,57 @@
# Setup
# Computer Vision
## Repository Organisation
### computer_vision
board_detection.py - Contains a ROS2 node that takes an image of a chessboard and identify the inner and outer corners of the chessboard, publishing whether coordinates have been found and their 2D image coordinates

### config
Contains camera configuration for the club webcam if using.

### test
Three basic tests and 3 images of random chessboards

### train
chess_piece_detection_training.py - Contains code to load data from roboflow and train a yolov8n model with it


## Setup

1. (Optional) If you are planning on training the YOLO model, copy `.roboflow_key.example` to `.roboflow_key`, get your Roboflow key and write it into the file
2. Get camera calibration and parameter files and put them into `config/cam_params.yaml` and `config/camera_info.yaml`. This can be done in 2 ways:
- Copy over the templates `config/cam_params_template.yaml` and `config/camera_info_template.yaml`. This is done by default in `install.py`.
- Calibrate the camera by yourself (See the section below).
- Calibrate the camera by yourself.

## TODO: add documentation for how to calibrate the camera
TODO: calibrate camera
TODO: optimise params

# Usage
## Running the nodes
## Usage
### Running the nodes
`board_detection` node doesn't use any extra parameters: just do `ros2 run computer_vision board_detection`

## Debugging
### Debugging
To start the camera node directly, run `ros2 run usb_cam usb_cam_node_exe --ros-args --params-file config/cam_params.yaml`

To simulate a camera with an image, run `ros2 run stub_scripts compressed_image_publisher --ros-args -p input_path:="test/test_images/chessboards/1.jpeg"`, where the image path can be replaced for other images
To simulate a camera with an image, run `ros2 run stub_scripts compressed_image_publisher --ros-args -p input_path:="src/computer_vision/test/test_images/chessboards/1.jpeg", where the image path can be replaced for other images

To view camera output, run `rqt`, select "Plugins/visualization/Image view" and select the correct topic


## Resources
### OpenCV
OpenCV Tutorial - https://www.youtube.com/watch?v=oXlwWbU8l2o

### YOLO
How YOLO works - https://www.youtube.com/watch?v=svn9-xV7wjk
YOLOv8 Model Specification - https://github.com/ultralytics/ultralytics/blob/main/docs/en/models/yolov8.md

### Camera Calibration
Monocular camera calibration using ROS - https://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration

### Roboflow
Roboflow Guide - https://blog.roboflow.com/train-yolov8-obb-model/

### Ros Intergration
YOLO integration - https://github.com/leggedrobotics/darknet_ros
Ultralytics integration - https://docs.ultralytics.com/guides/ros-quickstart/#use-ultralytics-with-ros-sensor_msgsimage

### Webcams
Using Android phone as a webcam - https://adityatelange.in/blog/android-phone-webcam-linux/
Physical Webcam model - https://amzn.eu/d/99ZbQrP

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ultralytics import YOLO

try:
with open(".roboflow_key", "r") as f:
with open("src/computer_vision/config/.roboflow_key", "r") as f:
ROBOFLOW_KEY = f.read().strip()
except FileNotFoundError:
from sys import exit, stderr
Expand All @@ -29,4 +29,4 @@

model = YOLO("yolov8n.pt")

results = model.train(data=f"{dataset.location}/data.yaml", epochs=100, imgsz=640)
results = model.train(data=f"{dataset.location}/data.yaml", epochs=100, imgsz=640, device="cpu", batch=8)