安装pytorch+yolov5+opencv-python+opecv-cpp

1. 安装Pytorch 

pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu

 运行Python

import torch
print(torch.__version__)

2. 安装YOLOv5 

$ git clone https://github.com/ultralytics/yolov5.git
$ cd yolov5
$ pip install -r requirements.txt

python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source data/images

pip install onnx

python export.py --weights outputs/weights/yolov5s.pt --img 640 --batch 1

pip install netron

import netron
netron.start('yolov5s.onnx')

 3. 安装opencv-python 

pip install opencv-python

import cv2
print(cv2.__version__)

 4. 安装opencv-c++

conda deactivate #退出anaconda环境,否则会出在编译时出现冲突

# Install minimal prerequisites (Ubuntu 18.04 as reference)
sudo apt update && sudo apt install -y cmake g++ wget unzip
# Download and unpack sources
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
unzip opencv.zip
# Create build directory
mkdir -p build && cd build
# Configure
cmake  ../opencv-4.x
# Build
cmake --build .

sudo make install

添加环境路径

vim .bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/include/opencv4

参考:

https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html

https://docs.opencv.org/4.x/db/df5/tutorial_linux_gcc_cmake.html

https://www.it610.com/article/1295232669759643648.htm

https://blog.csdn.net/qq_16792139/article/details/124079537

https://blog.csdn.net/qq_57841179/article/details/120652873

posted @ 2022-08-12 14:40  盛夏夜  阅读(178)  评论(0编辑  收藏  举报