Jetson nano 更新软件源 安装OpenCV 经验

一、更新nano的镜像源

之前一直用Ubuntu的PC系统,最近刚接触Jetson nano开发板,以为和之前的Ubuntu系统是一样的,但是直到最近要自己安装OpenCV才发现,两者其实是有区别的。
通过查看etc文件夹中的os-release文件可以看到,Nano系统的版本是ubuntu18.04LTS(Bionic Beaver),所以nano更新所使用的镜像源与PC系统的镜像源是不一样的。
首先,需要备份原来的源文件。

#切换到apt配置文件的目录
cd /etc/apt/
#备份source.list
sudo cp sources.list sources.list.bak

然后使用编辑器打开source.list文件

sudo gedit sources.list

将sources.list里面的内容全部替换为下面的清华源。

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe

更新源和软件

sudo apt-get update   
sudo apt-get upgrade  

二、安装OpenCV依赖项

在编译OpenCV前,首先安装相关的依赖包:

sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff5-dev libdc1394-22-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install libxvidcore-dev libx264-dev 
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install ffmpeg

三、安装依赖项报错解决方法

我就在这一步开始遇到了如下依赖项不匹配的问题:

nvidia@nvidia-desktop:~$ sudo apt-get install libgtk2.0-dev 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libgtk2.0-dev : Depends: libgdk-pixbuf2.0-dev (>= 2.21.0) but it is not going to be installed
                 Depends: libpango1.0-dev (>= 1.20) but it is not going to be installed
                 Depends: libatk1.0-dev (>= 1.29.2) but it is not going to be installed
                 Depends: libcairo2-dev (>= 1.6.4-6.1) but it is not going to be installed
                 Depends: libxinerama-dev (>= 1:1.0.1-4.1) but it is not going to be installed
                 Depends: libxcursor-dev but it is not going to be installed
                 Depends: libxcomposite-dev (>= 1:0.2.0-3) but it is not going to be installed
                 Recommends: debhelper but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

这里的错误可能是和换源有关系,但是我换了好多个源还是不好用,在网上找了很多办法都没解决,这里提示大家千万千万不能使用sudo apt-get install aptitude的方法,因为安装了aptitude之后apt就不能使用了的。网上有一种方法是卸载aptitude,再下载一个apt的安装包来安装,但是根本没有arm64的apt安装包,至少我没找到。最后没辙我重新刷的image。

解决方法: 打开system settings>>Software&Updates,将Ubuntu Software一栏中Downloadable from the internet中五个选项选中,将Updates一栏中Install updates from:下面前两条选项选中,然后close。
这样之后再安装libgtk2.0-dev就不会再报依赖错误了!
后来发现,这样设置之后在源文件里又被加入了ubuntu官方的源地址。

sudo apt-get install libgtk2.0-dev

四、下载编译OpenCV

网址链接为:https://opencv.org/releases/
Github地址:https://github.com/opencv/opencv/releases/tag/3.4.5

下载好的资源解压到home目录下,在文件夹中打开终端执行

 mkdir build
 cd build
 cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local \
        -D WITH_CUDA=ON -D CUDA_ARCH_BIN="5.3" -D CUDA_ARCH_PTX="" \
        -D WITH_CUBLAS=ON -D ENABLE_FAST_MATH=ON -D CUDA_FAST_MATH=ON \
        -D ENABLE_NEON=ON -D WITH_LIBV4L=ON -D BUILD_TESTS=OFF \
        -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF \
        -D WITH_OPENGL=ON -D BUILD_OPENCV_DNN=ON ..

因为Nano是四核,所以用-j4

sudo make -j4
sudo make install

等待编译完成。

参考链接:

【1】: https://blog.csdn.net/gj295983859/article/details/95182810
【2】: https://blog.csdn.net/qq_36396941/article/details/88903094

猜你喜欢

转载自blog.csdn.net/qq_43019451/article/details/103292910