【Jetson AGX Xavier】安装 opencv4.5支持gstreamer

nvidia@nvidia-desktop:~$ jetson_release
 - NVIDIA Jetson AGX Xavier [16GB]
   * Jetpack 4.5.1 [L4T 32.5.1]
   * NV Power Mode: MODE_30W_ALL - Type: 3
   * jetson_stats.service: active

我要在 Xavier 上安装支持 gstreamer 的 opencv-4.5.0,首先从官网上下载 opencv-4.5.0的源码,尝试了一下发现直接用迅雷下载 zip 包比较快。

安装依赖包

sudo apt install gstreamer1.0*
sudo apt install ubuntu-restricted-extras
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

编译安装

cd opencv-4.5.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \ #安装路径,可以指定按默认路径安装
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D PYTHON_EXECUTABLE=$(which python2) \
-D BUILD_opencv_python2=OFF \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D WITH_GSTREAMER = ON \ #这个一定要打开
-D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
 ..

【Jetson AGX Xavier】安装 opencv4.5支持gstreamer_第1张图片

确保 GStreamer 选项开关为 YES,否则要检查cmake 编译中报出的错误。

make -j8 #编译

sudo make install  #安装

######问题1

root@ff2ae4aa882a:~/hive/repository/opencv/opencv-4.5.0/build# pip3 install opencv-python
Collecting opencv-python
  Downloading https://mirrors.bfsu.edu.cn/pypi/web/packages/bb/08/9dbc183a3ac6baa95fabf749ddb531bd26256edfff5b6c2195eca26258e9/opencv-python-4.5.1.48.tar.gz (88.3MB)
    100% |################################| 88.3MB 7.7kB/s
Collecting numpy>=1.19.3 (from opencv-python)
  Downloading https://mirrors.bfsu.edu.cn/pypi/web/packages/51/60/3f0fe5b7675a461d96b9d6729beecd3532565743278a9c3fe6dd09697fa7/numpy-1.19.5.zip (7.3MB)
    100% |################################| 7.3MB 87kB/s
Building wheels for collected packages: opencv-python, numpy

...这里会卡着一动不动......需要升级 pip3

pip3 install --upgrade pip

######问题2

root@ff2ae4aa882a:~/hive/repository/opencv/opencv-4.5.0/build# python3
Python 3.6.9 (default, Jan 26 2021, 15:33:00)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Illegal instruction (core dumped)

需要安装特定版本的numpy

root@ff2ae4aa882a:~/hive/repository/opencv/opencv-4.5.0/build# pip3 install numpy==1.19.4
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Looking in indexes: https://pypi.mirrors.ustc.edu.cn/simple/
Collecting numpy==1.19.4
  Downloading https://mirrors.bfsu.edu.cn/pypi/web/packages/c6/0d/ffa6487298f7b626746fd1be54636075916888f30ea8d6e7d1c4cfaeb7f6/numpy-1.19.4-cp36-cp36m-manylinux2014_aarch64.whl (12.2 MB)
     |################################| 12.2 MB 1.3 MB/s
Installing collected packages: numpy
  Attempting uninstall: numpy
    Found existing installation: numpy 1.19.5
    Uninstalling numpy-1.19.5:
      Successfully uninstalled numpy-1.19.5
Successfully installed numpy-1.19.4

你可能感兴趣的:(ros,xavier,OpenCV实战,opencv,gstream)