# YOLOv8
> [name=江廷威 (twc+contact@aleeas.com)]
## Tools used
- [Ultralytics](https://docs.ultralytics.com/#how-can-i-get-started-with-yolo-installation-and-setup)
- [Roboflow](https://roboflow.com/)
- [Kaggle](https://www.kaggle.com/) / [Colab](https://colab.google/)
## Install
reference: https://docs.ultralytics.com
```
pip install ultralytics
```
## Data collection
### Capture video
This is the code for recording mp4 video using opencv, note that we should set the correct ***height*** and ***width*** supported for the camera.
We are saving mp4 video because the [lableing tool](#Labeling) we use only support mp4 video or images.
```python=
import cv2
cap = cv2.VideoCapture(0)
cap.set(3,640) # width
cap.set(4,480) # height
fourcc = cv2.VideoWriter_fourcc(*'MP4V')
out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (640,480)) # (width, height)
while(True):
ret, frame = cap.read()
out.write(frame)
cv2.imshow('frame', frame)
c = cv2.waitKey(1)
if c & 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()
```
### Labeling
There are many labeling tools out there, here we use https://roboflow.com/
1. Upload video or images

2. Assign labeling work to teammates

3. Label the ball

4. Export data

## Train
Training without GPU is ***extremely slow***. If you don't have a GPU, use kaggle or google colab.
Use this [jupyter notebook](https://github.com/NCTU-AUV/yolov8-training/blob/master/yolov8.ipynb) to train on kaggle and export to .onnx format
1. Upload a yolov8 (.zip file) dataset to kaggle.
2. Change the name of the dataset in the notebook.
3. Run all
4. Download `best.onnx`
## Predict
refer to: https://hackmd.io/5pV_GR3qSLqnGV9uZBOLpg#isaac_ros_yolov8