先移除之前刷机时TX2板上的OpenCV版本
$ sudo apt-get purge libopencv*
$ sudo apt-get purge python-numpy
$ sudo apt autoremove
$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo apt-get install --only-upgrade g++-5 cpp-5 gcc-5
$ sudo apt-get install build-essential make cmake cmake-curses-gui \
g++ libavformat-dev libavutil-dev \
libswscale-dev libv4l-dev libeigen3-dev \
libglew-dev libgtk2.0-dev
$ sudo apt-get install libdc1394-22-dev libxine2-dev \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev
$ sudo apt-get install libjpeg8-dev libjpeg-turbo8-dev libtiff5-dev \
libjasper-dev libpng12-dev libavcodec-dev
$ sudo apt-get install libxvidcore-dev libx264-dev libgtk-3-dev \
libatlas-base-dev gfortran
$ sudo apt-get install libopenblas-dev liblapack-dev liblapacke-dev
$ sudo apt-get install qt5-default
安装支持python2的numpy和matplotlib,使用pip安装效果更佳
$ sudo apt-get install python3-dev python3-pip python3-tk
$ sudo pip3 install numpy
$ sudo pip3 install matplotlib
将第41行修改为 backend : TkAgg
$ sudo vim /usr/local/lib/python3.5/dist-packages/matplotlib/mpl-data/matplotlibrc
同样安装支持python2的numpy和matplotlib
$ sudo apt-get install python-dev python-pip python-tk
$ sudo pip2 install numpy
$ sudo pip2 install matplotlib
将第41行修改为 backend : TkAgg
$ sudo vim /usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/matplotlibrc
我在sudo pip2 install matplotlib会报错,错误显示:
The directory '/home/nvidia/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/nvidia/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting matplotlib
Downloading https://files.pythonhosted.org/packages/89/0c/653aec68e9cfb775c4fbae8f71011206e5e7fe4d60fcf01ea1a9d3bc957f/matplotlib-3.0.2.tar.gz (36.5MB)
100% |████████████████████████████████| 36.5MB 11kB/s
Complete output from command python setup.py egg_info:
Matplotlib 3.0+ does not support Python 2.x, 3.0, 3.1, 3.2, 3.3, or 3.4.
Beginning with Matplotlib 3.0, Python 3.5 and above is required.
This may be due to an out of date pip.
Make sure you have pip >= 9.0.1.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-gru1jx/matplotl
sudo -H pip2 install matplotlib
成功安装
nvidia@tegra-ubuntu:$ sudo -H pip2 install matplotlib
Collecting matplotlib
Downloading https://files.pythonhosted.org/packages/eb/a0/31b6ba00bc4dcbc06f0b80d1ad6119a9cc3081ecb04a00117f6c1ca3a084/matplotlib-2.2.3.tar.gz (36.8MB)
100% |████████████████████████████████| 36.8MB 66kB/s
Requirement already satisfied: numpy>=1.7.1 in /usr/local/lib/python2.7/dist-packages (from matplotlib) (1.15.4)
Collecting cycler>=0.10 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/71/e8/6777f6624681c8b9701a8a0a5654f3eb56919a01a78e12bf3c73f5a3c714/pyparsing-2.3.0-py2.py3-none-any.whl (59kB)
100% |████████████████████████████████| 61kB 60kB/s
Collecting python-dateutil>=2.1 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/74/68/d87d9b36af36f44254a8d512cbfc48369103a3b9e474be9bdfe536abfc45/python_dateutil-2.7.5-py2.py3-none-any.whl (225kB)
100% |████████████████████████████████| 235kB 68kB/s
Collecting pytz (from matplotlib)
Downloading https://files.pythonhosted.org/packages/f8/0e/2365ddc010afb3d79147f1dd544e5ee24bf4ece58ab99b16fbb465ce6dc0/pytz-2018.7-py2.py3-none-any.whl (506kB)
100% |████████████████████████████████| 512kB 69kB/s
Collecting six>=1.10 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting kiwisolver>=1.0.1 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/31/60/494fcce70d60a598c32ee00e71542e52e27c978e5f8219fae0d4ac6e2864/kiwisolver-1.0.1.tar.gz
Collecting backports.functools_lru_cache (from matplotlib)
Downloading https://files.pythonhosted.org/packages/03/8e/2424c0e65c4a066e28f539364deee49b6451f8fcd4f718fefa50cc3dcf48/backports.functools_lru_cache-1.5-py2.py3-none-any.whl
Collecting subprocess32 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/be/2b/beeba583e9877e64db10b52a96915afc0feabf7144dcbf2a0d0ea68bf73d/subprocess32-3.5.3.tar.gz (96kB)
100% |████████████████████████████████| 102kB 71kB/s
Requirement already satisfied: setuptools in /usr/lib/python2.7/dist-packages (from kiwisolver>=1.0.1->matplotlib) (20.7.0)
Building wheels for collected packages: matplotlib, kiwisolver, subprocess32
Running setup.py bdist_wheel for matplotlib ... done
Stored in directory: /root/.cache/pip/wheels/08/76/86/68cad2489eccd36beb80adb37c3b260a76058fff95c9bcad19
Running setup.py bdist_wheel for kiwisolver ... done
Stored in directory: /root/.cache/pip/wheels/6a/74/52/d0be4cffbeb03598e085465ac97b3c0d0f5570c2be64744a95
Running setup.py bdist_wheel for subprocess32 ... done
Stored in directory: /root/.cache/pip/wheels/c0/08/48/bb468e57d688ea6fa40a450d88d7d9f5fb3c955510077da743
Successfully built matplotlib kiwisolver subprocess32
Installing collected packages: six, cycler, pyparsing, python-dateutil, pytz, kiwisolver, backports.functools-lru-cache, subprocess32, matplotlib
Successfully installed backports.functools-lru-cache-1.5 cycler-0.10.0 kiwisolver-1.0.1 matplotlib-2.2.3 pyparsing-2.3.0 python-dateutil-2.7.5 pytz-2018.7 six-1.12.0 subprocess32-3.5.3
$ sudo vim /usr/local/cuda/include/cuda_gl_interop.h
修改62-68行内容如下:
//#if defined(__arm__) || defined(__aarch64__)
//#ifndef GL_VERSION
//#error Please include the appropriate gl headers before including cuda_gl_interop.h
//#endif
//#else
#include
//#endif
$ cd /usr/lib/aarch64-linux-gnu/
$ sudo ln -sf tegra/libGL.so libGL.so
下载opencv-3.4.0.zip
$ mkdir -p ~/src
$ cd ~/src
$ wget https://github.com/opencv/opencv/archive/3.4.0.zip \
-O opencv-3.4.0.zip
$ unzip opencv-3.4.0.zip
### Build opencv (CUDA_ARCH_BIN="6.2" for TX2, or "5.3" for TX1)
$ cd ~/src/opencv-3.4.0
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_CUDA=ON -D CUDA_ARCH_BIN="6.2" -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_QT=ON -D WITH_OPENGL=ON ..
$ make -j4
$ sudo make install
验证安装
$ ls /usr/local/lib/python3.5/dist-packages/cv2.*
显示内容
/usr/local/lib/python3.5/dist-packages/cv2.cpython-35m-aarch64-linux-gnu.so
查看安装版本
$ python3 -c 'import cv2; print(cv2.__version__)'
3.4.0
$ python2 -c 'import cv2; print(cv2.__version__)'
3.4.0
我们利用opencv运行一下摄像头试一试效果。这是一段应用opencv调用摄像头识别出人脸的程序。
如果需要,下载连接:https://download.csdn.net/download/zhangziju/10875888