欢迎光临散文网 会员登陆 & 注册

树莓派4B安装ubuntu 20 ,opencv,pytorch,miniconda3,ncnn配置

2023-02-12 15:58 作者:飞的岛  | 我要投稿

树梅派型号:4B (64位)

安装系统为:ubuntu server 20.04.5 LTS (64-bit)

选择这个系统主要是考虑到通用性更好,后期的嵌入式人工智能的开发,基于ROS开发机器人。

1、下载镜像到SD中

如果需要连接wifi,看https://blog.csdn.net/weixin_42102084/article/details/122202710

2、安装系统桌面

安装桌面

apt-get install -y ubuntu-desktop

安装xrdp,xrdp是一个微软远程桌面协议(RDP)的开源实现,

它允许你通过图形界面控制远程系统

apt-get install -y xrdp

安装完成后,即可使用Windows远程桌面工具登录Ubuntu。

3、安装NoMachine,方便PC访问树梅派

我的系统是4B,可以用命令sudo uname -a

进入官方下载网页,https://downloads.nomachine.com/

下载版本,NoMachine for Raspberry ARMv8 TAR.GZ


打开downloads文件夹

cd Downloads/


将文件移动到/usr目录

sudo mv nomachinexxxxxx.tar.gz /usr


解压文件

cd /usr

sudo tar zxvf nomachinexxxxx.tar.gz

安装文件

sudo /usr/NX/nxserver --install

4、更换系统语言

可能这个时候你需要将系统换成中文的

settings -->  region&language --> manage installed languages

-->install / Remove Languages --> chansis simple

等等

5、换成国内的源


(1)更改文件权限使其可编辑


sudo chmod 777 /etc/apt/sources.list


(2)打开文件进行编辑


sudo gedit /etc/apt/sources.list


(3)删除原来的文件内容,复制对应的源(可以先用命令确认系统,lsb_release -a)

我的系统是ubuntu 20 focal,所以对应的源如下


deb https://mirrors.aliyun.com/ubuntu-ports/ focal main restricted universe multiverse

deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal main restricted universe multiverse


deb https://mirrors.aliyun.com/ubuntu-ports/ focal-security main restricted universe multiverse

deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal-security main restricted universe multiverse


deb https://mirrors.aliyun.com/ubuntu-ports/ focal-updates main restricted universe multiverse

deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal-updates main restricted universe multiverse


deb https://mirrors.aliyun.com/ubuntu-ports/ focal-backports main restricted universe multiverse

deb-src https://mirrors.aliyun.com/ubuntu-ports/ focal-backports main restricted universe multiverse


更新与升级

sudo apt-get update

sudo apt-get upgrade


6、pip换国内的源

临时使用

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

注意,simple 不能少, 是 https 而不是 http

设为默认

升级 pip 到最新的版本 (>=10.0.0) 后进行配置:

python -m pip install --upgrade pip

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:

python -m pip install -i https://pypi.tuna.

tsinghua.edu.cn/simple --upgrade pip



7、安装miniconda


先确定一下系统中的python版本(我的是3.8)

python --version


下载对应python版本的miniconda3,这里我尝试年多个版本,下面这个版本是成功

Miniconda3-py38_4.9.2-Linux-aarch64.sh

清华镜像下载网页,

https://mirrors.bfsu.edu.cn/anaconda/miniconda/



安装指令

bash Miniconda3xxxxxx.sh

安装完之后,退出终端,重新进入终端输入conda试试


问题解决——终端输入conda,出现未找到命令

解决办法:

终端输入:vim ~/.bashrc

键盘大写“G”,在最末端输入:export PATH=~/anaconda2/bin:$PATH

使其生效:source ~/.bashrc

打印验证:echo ~/.bashrc

然后再输入:conda


创建环境

conda create -n feidedaoPy37 python=3.7

source activate feidedaoPy37


安装spyder,就可以开始开发了

sudo apt-get install spyder


更改spyder使用conda 环境 ,在tool ---〉 interpreter----〉use,打开python,选择conda的环境

终端查询python路径命令whereis python


8.安装pytorch


通过pip指令直接安装,后期会掉用卷积时会出错

pip install torch torchvision

所以选择使用下载whl安装方式,cpu版本,下载链接

Links for torchvisionpypi.tuna.tsinghua.edu.cn/simple/torchvision/

Links for torchpypi.tuna.tsinghua.edu.cn/simple/torch/

对应我环境python3.8版本,所以选择torch-1.12  torchvision-0.13

安装指令 pip innstall .whl

对应版本


编辑


9、安装opencv


只用python进行开发,只需下面的方式

pip install opencv-python

pip install scikit learn


如果需要c++调用,需要进行源码编译

安装一些依赖项

sudo apt install build-essential

sudo apt install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

sudo apt install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev


如果出现libjasper-dev error,解决方案参考https://blog.csdn.net/m0_46324847/article/details/122764545

更改

sudo nano /etc/apt/sources.list

其中添加,注意不要改动

deb http://ports.ubuntu.com/ubuntu-ports xenial-security main

进行sudo apt update ,注意不要upgrade

安装sudo apt-get install libjasper-dev

完毕后,要把刚才在sources.list中添加的一行去掉


安装图像和视频操作库

sudo apt-get install libjpeg-dev libpng-dev libtiff-dev

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev

sudo apt-get install libxvidcore-dev libx264-dev


安装gtk

sudo apt-get install libgtk-3-dev

sudo apt-get install libcanberra-gtk*


安装opencv优化库

sudo apt-get install libatlas-base-dev gfortran


安装python3开发相关的库

sudo apt-get install python3-dev

sudo apt-get install libjasper-dev libjasper1


安装HDF5和QT库:

sudo apt-get install libhdf5-dev

sudo apt-get install libhdf5-serial-dev

sudo apt-get install libatlas-base-dev

sudo apt-get install libjasper-dev

sudo apt-get install libqtgui4

sudo apt-get install libqt4-test


下载相关的包

git clone https://github.com/opencv/opencv.git

git clone https://github.com/opencv/opencv_contrib.git


配置编译opencv

cd

cd opencv

mkdir build

cd build

sudo cmake -D BUILD_opencv_python3=YES -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..

https://blog.csdn.net/u013131455/article/details/110820516


开始编译

sudo make -j4

安装

sudo make install

最后还要进行一些 配置 ,见https://www.cnblogs.com/gghy/p/11916830.html


指令验证opencv是否安装成功

cd

python3

import CV2

CV2.__version__

出现对应版本就成功了




11、树梅派摄像头libcamera安装

https://blog.csdn.net/weixin_41756645/article/details/124461772

https://www.raspberrypi.com/documentation/computers/camera_software.html#binary-packages

注意,用这个版本可行raspi-config_20201108_all.deb,最新的版本总是出错



12、树梅派4b安装ncnn


https://blog.csdn.net/u010518385/article/details/116701542

https://blog.csdn.net/weixin_41012767/article/details/124836471


https://github.com/Tencent/ncnn/wiki/how-to-build#pass-for-linux


注意:测试

build $ cd ../examples/

examples $ ../build/examples/squeezenet ../images/256-ncnn.png

参考cmake配置

cmake -D CMAKE_BUILD_TYPE=Release  -D NCNN_BUILD_BENCHMARK=ON -D NCNN_BUILD_EXAMPLES=ON -D NCNN_BUILD_TOOLS=ON -D NCNN_BUILD_TESTS=ON -D NCNN_PYTHON=ON  -D NCNN_VULKAN=OFF   ..


在安装中,我也难免会遇到问题,只能上网多找解决方案


参考:

https://www.zhihu.com/question/422066655/answer/2777429042

https://zhuanlan.zhihu.com/p/587172802

https://blog.csdn.net/qq_38228260/article/details/126320747

https://developer.aliyun.com/article/762186

https://blog.csdn.net/lzzzzzzm/article/details/119714119

https://blog.csdn.net/qq_47842513/article/details/118695211

https://blog.csdn.net/m0_46324847/article/details/122764545

https://www.yahboom.com/build/id/4155/cid/308


树莓派4B安装ubuntu 20 ,opencv,pytorch,miniconda3,ncnn配置的评论 (共 条)

分享到微博请遵守国家法律