Machine Vision Technology Development
Experiment 4 - YOLOv5 Object Detection
Experiment steps:
- Need to install python3, opencv, conda environment. (Can skip if already installed, can refer to experiments 1-3 for environment installation process)
- Clone YOLOv5 model, enter command in terminal: git clone https://github.com/ultralytics/yolov5

cp -r /home/sunrise/yolov5 /home/sunrise/OPENCV/# Copy yolov5 package to function package
cd OPENCV
pip install -r /home/sunrise/OPENCV/requirements_yolov5_torch.txt(Install minimum dependencies for YOLOv5 to run)

source rdkx5_vision_env/bin/activate# Activate virtual environmentInstall related packages:
In OPENCV directory
First upgrade pip: python -m pip install --upgrade pip
Run the following command:
pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu)
pip install ultralytics
pip install pandas psutil thop scipy
python -m pip install tqdmIt is recommended to install together as they may be used later: python -m pip install pandas psutil thop pillow pyyaml requests matplotlib seaborn
(The following steps can be skipped first, try running the sample file first, if version dependency is too low and cannot run the model, then update:
Upgrade basic installation tools: python -m pip install -U pip wheel setuptools==70.0.0
Install/upgrade missing dependencies: python -m pip install -U gitpython pillow==10.3.0
)
cd yolov5# Enter packagepython detect.py --weights yolov5s.pt --source 0# Run camera version sample file, ensure camera is connected properly
Terminal prints as follows:


If no camera is available, you can choose local image or video import:
Use local image for quick verification
python detect.py --weights yolov5s.pt --source path\to\image.jpg# Change to image path after sourceUse video file for verification
python detect.py --weights yolov5s.pt --source path\to\video.mp4# Change to video path after source
