opencv4를 jetson nano에 qemu로 설치해보자

mrzjo·2022년 3월 23일
1

jetson-nano

목록 보기
2/2
post-thumbnail

abstract

Jetson nano, 특히 emmc 버전을 사용하는 경우 16GB의 emmc 용량과 4GB의 RAM으로 인한 제한으로 인해 opencv와 같은 굉장히 덩치가 큰 프로젝트를 customizing하기 위해 build를 해서 사용하기가 어렵다. 이 과정의 어려움은 아래와 같다.

  1. opencv는 ram의 크기가 8G이상이지 않으면 build 도중에 중단이 되는 문제가 종종 있다.
  2. ram의 크기를 8GB인 것 처럼 swap memory 4GB를 eMMC나 SD card에 추가하여 확장할 수 있다. 하지만 eMMC의 경우 16GB밖에 용량이 없고 linux kernel과 nvidia에서 제공하는 기본적인 filesystem에서 6~7GB, cuda 설치용 library 2~3GB하면 벌써 10GB 가까이 사용한다.
    남은 6GB에서 swap memory 4GB를 수탈당하면 opencv build는 정신건강을 해칠 수 있다.

그래서 풍족한 호스트 환경에서 빌드하고 꼭 필요한 파일들 만 복사해서 사용하면 jetson의 용량을 아낄수 있다.

상당히 많은 파일을 다운로드 하게 되므로 인터넷이 빠른 곳에서 작업하는 것을 추천한다.

참조한 링크

https://codepyre.com/2019/08/building-custom-root-filesystems/#chroot-there-it-is
https://yunslog.tistory.com/53

사양

required SW packages

host

  • Ubuntu 18.04
  • VMware Workstation 16 Player
    • ram 8G
    • storage 100G
    • core 수가 많을수록, ram이 클수록 build가 빨라진다.
      가능한한 최대로 설정한다.

target

  • Jetson nano eMMC
  • Telelian vs301


host

  • host에서 할 일. target(jetson)에서 할 일은 아래에 별도로 구분.

qemu

qemu는 무엇인가?

  • 나무 위키에서 알 수 있듯이 여러 플랫폼을 에뮬레이션 할 수 있는 오픈소스 툴이다.
  • 이번엔 arm64를 에뮬레이션하기 위해 사용한다.

install

sudo apt update
sudo apt install -y qemu-user-static debootstrap 

make rootfs

  • linux의 root filesystem을 생성하고 jetson에서 사용할 ubuntu 18.04 (bionic)의 root를 에뮬레이션한다.
  • work directory를 /home/$USER/work에 있다고 가정.
~/work$ mkdir rootfs
# 아래 명령으로 arm64용 library들과 daemon들을 받고 설치함. 꽤 걸림.
~/work$ sudo qemu-debootstrap --arch arm64 bionic ./rootfs
~/work$ sudo chroot ~/work/rootfs
  • 여기까지 실행하면 명령 프롬프트가 바뀐다.
    • 이제 arm emulation이 시작된다.
root@ubuntu:/#
  • 이제 부터 프롬프트는 $로 표기.
  • 제대로 됐는지 확인.
    • aarch 64가 나오면 ok. arm64의 또 다른 이름.
$ uname -m
aarch64

update & install packages in qemu

$ cat /etc/apt/sources.list
deb http://ports.ubuntu.com/ubuntu-ports bionic main
  • 기본 source.list에 위의 서버 밖에 없는데 저러면 수많은 패키지가 설치가 안된다. 아래 명령으로 파일 교체
$ echo "# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic universe
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security universe
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security multiverse

deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted" > /etc/apt/sources.list
  • 본격 설치 시작
$ apt update
$ apt install --no-install-recommends -y curl wget unzip gnupg1 git build-essential \
    cmake git ccache pkg-config \
	libavcodec-dev libavformat-dev libswscale-dev \
    libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
    libfreetype6 libfreetype6-dev libharfbuzz-dev \
    libgflags-dev liblapack-dev \
    libopenblas-dev libatlas3-base libbliss2 gfortran liblapack3 libeigen3-dev \
    libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev \
    libdc1394-22-dev \
    libv4l-dev v4l-utils qv4l2 v4l2ucp \
	mesa-utils libgl1-mesa-dri \
    python3-pip python3-dev python3-numpy \
    qt5-default qttools5-dev libqt5opengl5-dev

install cuda & libcudnn

  • 위에 있는 required SW package의 sdkmanager를 이용해 필요한 패키지를 다운로드하자.
  • 아래의 파일들이 있다면 sdkmanager는 설치할 필요 없다.
  • 필요한 파일 리스트 (jetpack 4.6.1의 경우)
    • cuda-repo-l4t-10-2-local_10.2.460-1_arm64.deb
    • libcudnn8_8.2.1.32-1+cuda10.2_arm64.deb
    • libcudnn8-dev_8.2.1.32-1+cuda10.2_arm64.deb
    • libcudnn8-samples_8.2.1.32-1+cuda10.2_arm64.deb
  • 필요한 파일 리스트 (다른 버전의 jetpack의 경우 파일명은 비슷하고 cuda version과 libcudnn의 버전만 다르다.)
    • cuda-repo-l4t-{cudaversion}-local{cuda_version}.{cuda_version_revision}-1_arm64.deb
    • libcudnn8_{cudnn8_version}-1+cuda{cuda_version}_arm64.deb
    • libcudnn8-dev_{cudnn8_version}-1+cuda{cuda_version}_arm64.deb
    • libcudnn8-samples_{cudnn8_version}-1+cuda{cuda_version}_arm64.deb

install sdkmanager

jetson sdkmanager 설치법

dpkg install cuda & cudnn

  • x86 host에서 확보한 cuda, cudnn 설치파일을 arm64용 rootfs/tmp로 옮긴다.
$ cp cuda-repo-l4t-10-2-local_10.2.460-1_arm64.deb libcudnn8* ~/work/rootfs/tmp/
  • arm64 에뮬레이터에서 아래 명령을 실행한다.
$ cd /tmp
$ dpkg -i cuda-repo-l4t-10-2-local_10.2.460-1_arm64.deb
$ apt-key add /var/cuda-repo-l4t-10-2-local/7fa2af80.pub
$ apt update
$ apt install -y cuda-toolkit-10-2 libgomp1 libfreeimage-dev libopenmpi-dev openmpi-bin
$ dpkg --purge cuda-repo-l4t-10-2-local
$ dpkg -i libcudnn8*

$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
$ export CUDA_HOME=/usr/local/cuda
$ export PATH=$PATH:$CUDA_HOME/bin

install opencv

  • build는 /tmp에서 설치는 /opt에
  • CUDA_ARCH_BIN의 설정값은 nano의 경우 5.3
    • 출처
    • 설정 안하면 모든 hardware를 지원하도록 빌드되는데 시간과 용량을 아끼려면 특정해 두는 것이 좋다.
$ cd /tmp
$ mkdir opencv
$ cd opencv

$ wget https://github.com/opencv/opencv/archive/refs/tags/4.5.1.tar.gz -O opencv-4.5.1.tar.gz
$ wget https://github.com/opencv/opencv_contrib/archive/refs/tags/4.5.1.tar.gz -O opencv_contrib-4.5.1.tar.gz

$ tar xvzf opencv-4.5.1.tar.gz
$ tar xvzf opencv_contrib-4.5.1.tar.gz

$ cd opencv-4.5.1
$ mkdir build
$ cd build

$ cmake -D OPENCV_GENERATE_PKGCONFIG=ON \
    -D OPENCV_PC_FILE_NAME=opencv.pc \
    -D WITH_CUDA=ON \
    -D CUDA_ARCH_BIN="5.3" \
    -D CUDA_ARCH_PTX="" \
    -D USE_NEON=ON \
    -D WITH_CUBLAS=ON -D WITH_CUDNN=ON \
    -D ENABLE_FAST_MATH=ON -D CUDA_FAST_MATH=ON \
    -D WITH_EIGEN=ON -D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
    -D WITH_GTK=OFF -D WITH_QT=ON -D WITH_OPENGL=ON\
    -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.5.1/modules \
    -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON \
    -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=ON \
    -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF \
    -D CMAKE_BUILD_TYPE=RELEASE \
    -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.2 \
    -D CUDNN_INCLUDE_DIRS=/usr/include/ \
    -D CUDNN_LIBRARIES=/usr/lib/aarch64-linux-gnu \
    -D CMAKE_INSTALL_PREFIX=/opt/opencv-4.5.1 \
    ..
  • cmake 까지 하면 아래 같이 출력되면 다음으로 진행.

    펼침
    -- General configuration for OpenCV 4.5.1 =====================================
    --   Version control:               unknown
    --
    --   Extra modules:
    --     Location (extra):            /tmp/opencv/opencv_contrib-4.5.1/modules
    --     Version control (extra):     unknown
    --
    --   Platform:
    --     Timestamp:                   2022-03-23T07:22:10Z
    --     Host:                        Linux 5.4.0-65-generic aarch64
    --     CMake:                       3.10.2
    --     CMake generator:             Unix Makefiles
    --     CMake build tool:            /usr/bin/make
    --     Configuration:               RELEASE
    --
    --   CPU/HW features:
    --     Baseline:                    NEON FP16
    --
    --   C/C++:
    --     Built as dynamic libs?:      YES
    --     C++ standard:                11
    --     C++ Compiler:                /usr/bin/c++  (ver 7.5.0)
    --     C++ flags (Release):         -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    --     C++ flags (Debug):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    --     C Compiler:                  /usr/bin/cc
    --     C flags (Release):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    --     C flags (Debug):             -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
    --     Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed
    --     Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed
    --     ccache:                      YES
    --     Precompiled headers:         NO
    --     Extra dependencies:          m pthread /usr/lib/aarch64-linux-gnu/libGL.so /usr/lib/aarch64-linux-gnu/libGLU.so cudart_static dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda-10.2/lib64 -L/usr/lib/aarch64-linux-gnu
    --     3rdparty dependencies:
    --
    --   OpenCV modules:
    --     To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
    --     Disabled:                    world
    --     Disabled by dependency:      -
    --     Unavailable:                 cnn_3dobj hdf java julia matlab ovis python2 sfm ts viz
    --     Applications:                apps
    --     Documentation:               NO
    --     Non-free algorithms:         NO
    --
    --   GUI:
    --     QT:                          YES (ver 5.9.5)
    --       QT OpenGL support:         YES (Qt5::OpenGL 5.9.5)
    --     OpenGL support:              YES (/usr/lib/aarch64-linux-gnu/libGL.so /usr/lib/aarch64-linux-gnu/libGLU.so)
    --     VTK support:                 NO
    --
    --   Media I/O:
    --     ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
    --     JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
    --     WEBP:                        build (ver encoder: 0x020f)
    --     PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.34)
    --     TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.0.9)
    --     JPEG 2000:                   build (ver 2.3.1)
    --     OpenEXR:                     build (ver 2.3.0)
    --     HDR:                         YES
    --     SUNRASTER:                   YES
    --     PXM:                         YES
    --     PFM:                         YES
    --
    --   Video I/O:
    --     DC1394:                      YES (2.2.5)
    --     FFMPEG:                      YES
    --       avcodec:                   YES (57.107.100)
    --       avformat:                  YES (57.83.100)
    --       avutil:                    YES (55.78.100)
    --       swscale:                   YES (4.8.100)
    --       avresample:                NO
    --     GStreamer:                   YES (1.14.5)
    --     v4l/v4l2:                    YES (linux/videodev2.h)
    --
    --   Parallel framework:            pthreads
    --
    --   Trace:                         YES (with Intel ITT)
    --
    --   Other third-party libraries:
    --     Lapack:                      NO
    --     Eigen:                       YES (ver 3.3.4)
    --     Custom HAL:                  YES (carotene (ver 0.0.1))
    --     Protobuf:                    build (3.5.1)
    --
    --   NVIDIA CUDA:                   YES (ver 10.2, CUFFT CUBLAS FAST_MATH)
    --     NVIDIA GPU arch:             53
    --     NVIDIA PTX archs:
    --
    --   cuDNN:                         YES (ver 8.2.1)
    --
    --   OpenCL:                        YES (no extra features)
    --     Include path:                /tmp/opencv/opencv-4.5.1/3rdparty/include/opencl/1.2
    --     Link libraries:              Dynamic load
    --
    --   Python 3:
    --     Interpreter:                 /usr/bin/python3 (ver 3.6.9)
    --     Libraries:                   /usr/lib/aarch64-linux-gnu/libpython3.6m.so (ver 3.6.9)
    --     numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.13.3)
    --     install path:                lib/python3.6/dist-packages/cv2/python-3.6
    --
    --   Python (for build):            /usr/bin/python3
    --
    --   Java:
    --     ant:                         NO
    --     JNI:                         NO
    --     Java wrappers:               NO
    --     Java tests:                  NO
    --
    --   Install to:                    /opt/opencv-4.5.1
    -- -----------------------------------------------------------------
    --
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /tmp/opencv/opencv-4.5.1/build
  • make

    • 이게 가장 오래 걸리는 작업이다.
    • host pc와 virtual machine의 사양에 따라 2-3시간에서 하루 이상도 소요될 수 있다.
$ make -j$(nproc) 
$ make install

to the target

  • target board에 복사하기 위한 준비
  • make install 까지 완료했으면 cmake 할 때 지정했던 위치에 build된 결과물이 준비되어 있다.
    • 지금은 -D CMAKE_INSTALL_PREFIX=/opt/opencv-4.5.1 옵션을 줬으므로 아래 폴더를 확인.
    $ cd /opt
    $ du -d1 -h
    210M	./opencv-4.5.1  
    $ cd /opt/opencv-4.5.1
    $ ls
    bin  include  lib  share  

압축

$ cd /opt
$ tar cvzf opencv-4.5.1_release.tar.gz ./opencv-4.5.1
  • 이제 opencv binary가 준비됐다.

마무리

$ exit
  • exit를 하면 emulation이 종료되고 x86 mode로 돌아온다.
    위의 안내대로 진행했으면 ~/work/rootfs/opt에 opencv-4.5.1_release.tar.gz 가 존재한다.
    이 파일을 jetson nano board로 복사한다.

  • jetson nano에 cuda, libcudnn이 깔리지 않았다면 아래 파일들도 복사한다.

    • 필요한 파일 리스트 (jetpack 4.6.1의 경우)
      • cuda-repo-l4t-10-2-local_10.2.460-1_arm64.deb
      • libcudnn8_8.2.1.32-1+cuda10.2_arm64.deb
      • libcudnn8-dev_8.2.1.32-1+cuda10.2_arm64.deb
      • libcudnn8-samples_8.2.1.32-1+cuda10.2_arm64.deb
    • 필요한 파일 리스트 (다른 버전의 jetpack의 경우)
      • cuda-repo-l4t-{cudaversion}-local{cuda_version}.{cuda_version_revision}-1_arm64.deb
      • libcudnn8_{cudnn8_version}-1+cuda{cuda_version}_arm64.deb
      • libcudnn8-dev_{cudnn8_version}-1+cuda{cuda_version}_arm64.deb
      • libcudnn8-samples_{cudnn8_version}-1+cuda{cuda_version}_arm64.deb

target

  • 이제부터 jetson nano에서 해야할 작업.
  • 여기에도 work 폴더를 만들고 시작한다.
    • 위에서 필요한 파일들을 work 폴더로 복사해 둘 것.
    • 이 부분의 설명은 생략. work 폴더에 파일들이 있다고 가정.
  • qemu에서 했던 opencv build와 make rootfs를 제외한 작업을 다시 해줘야 한다.
    • 다시 반복 설명할 예정이므로 위로 돌아갈 필요없다.
    • sudo가 추가되거나 sources.list에 추가할 작업등 미묘하게 다른 부분이 있으므로 target board에선 아래대로 진행한다.

update & install packages in jetson nano

$ sudo echo "deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted" >> /etc/apt/sources.list
$ sudo apt update
$ sudo apt install --no-install-recommends -y curl wget unzip gnupg1 git build-essential \
    cmake git ccache pkg-config \
	libavcodec-dev libavformat-dev libswscale-dev \
    libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
    libfreetype6 libfreetype6-dev libharfbuzz-dev \
    libgflags-dev liblapack-dev \
    libopenblas-dev libatlas3-base libbliss2 gfortran liblapack3 libeigen3-dev \
    libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev \
    libdc1394-22-dev \
    libv4l-dev v4l-utils qv4l2 v4l2ucp \
	mesa-utils libgl1-mesa-dri \
    python3-pip python3-dev python3-numpy \
    qt5-default qttools5-dev libqt5opengl5-dev

install cuda & cudnn

$ cd ~/work
$ sudo dpkg -i cuda-repo-l4t-10-2-local_10.2.460-1_arm64.deb
$ sudo apt-key add /var/cuda-repo-l4t-10-2-local/7fa2af80.pub
$ sudo apt update
$ sudo apt install -y cuda-toolkit-10-2 libgomp1 libfreeimage-dev libopenmpi-dev openmpi-bin
$ sudo dpkg --purge cuda-repo-l4t-10-2-local
$ sudo dpkg -i libcudnn8*

$ export LD_LIBRARY_PATH=/opt/opencv-4.5.1/lib:/usr/local/cuda/lib64:$LD_LIBRARY_PATH
$ export PATH=/opt/opencv-4.5.1/bin:/usr/local/cuda/bin:$PATH

$ ldconfig
  • 다시 로그인을 했을 때 PATH가 남아있어야 하므로 ~/.bashrc 에 아래 두줄 추가.
    • 다른 shell을 쓴다면 그에 맞는 file에 쓸 것
export LD_LIBRARY_PATH=/opt/opencv-4.5.1/lib:/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export PATH=/opt/opencv-4.5.1/bin:/usr/local/cuda/bin:$PATH

copy & setup opencv

  • 이제 거의 다 왔다.
$ cd /opt
$ sudo tar xvzf ~/work/opencv-4.5.1_release.tar.gz
  • python3에서 cv2를 쓸수 있게 연결
$ sudo ln -s /opt/opencv-4.5.1/lib/python3.6/dist-packages/cv2 /usr/lib/python3/dist-packages/cv2

test

  • 설치가 잘 됐는지 확인을 해보자.

jtop

  • shell 에서 jtop을 실행하고 숫자6을 눌러서 아래와 같이 나오면 성공
  • Libraries의 CUDA, OpenCV, cuDNN을 확인할 것.
  • Cuda ARCH는 원래 53이 표시돼야 하지만 L4T 32.7.1과 jtop이 호환이 안되는 부분이 있어서 NONE으로 표시된다고 함.
$ jtop
# 실행 중 숫자 6을 입력

  • jtop 실행이 안되고 없다고 나오면 아래 명령어 실행 후 터미널을 껐다가 재접속 한다.
$ sudo -H pip3 install -U jetson-stats
$ sudo systemctl restart jetson-stats

python3

  • 아래의 확인 코드는 python3 실행 후 REPL mode 임.

cv2

  • opencv 4.5.1을 깔았으니 version 이 맞나 확인
  • cuda device 확인
>>> import cv2
>>> cv2.__version__
'4.5.1'
>>> cv2.cuda.printCudaDeviceInfo(0)
*** CUDA Device Query (Runtime API) version (CUDART static linking) ***

Device count: 1

Device 0: "NVIDIA Tegra X1"
  CUDA Driver Version / Runtime Version          10.20 / 10.20
  CUDA Capability Major/Minor version number:    5.3
  Total amount of global memory:                 3964 MBytes (4156764160 bytes)
  GPU Clock Speed:                               0.92 GHz
  Max Texture Dimension Size (x,y,z)             1D=(65536), 2D=(65536,65536), 3D=(4096,4096,4096)
  Max Layered Texture Size (dim) x layers        1D=(16384) x 2048, 2D=(16384,16384) x 2048
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 32768
  Warp size:                                     32
  Maximum number of threads per block:           1024
  Maximum sizes of each dimension of a block:    1024 x 1024 x 64
  Maximum sizes of each dimension of a grid:     2147483647 x 65535 x 65535
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and execution:                 Yes with 1 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            Yes
  Support host page-locked memory mapping:       Yes
  Concurrent kernel execution:                   Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support enabled:                No
  Device is using TCC driver mode:               No
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Bus ID / PCI location ID:           0 / 0
  Compute Mode:
      Default (multiple host threads can use ::cudaSetDevice() with device simultaneously)

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version  = 10.20, CUDA Runtime Version = 10.20, NumDevs = 1

>>>

pyqt5

>>> import PyQt5.QtCore
>>> PyQt5.QtCore.QT_VERSION_STR
'5.9.5'

대단히 수고 하셨습니다!

profile
telelian

2개의 댓글

comment-user-thumbnail
2022년 3월 23일

우와~~~멋지십니다.

1개의 답글