deepStream learning 0 ---- environment construction (Ubuntu 18.04 + vscode + docker + deepStream + opencv + C + +)

Tools used:

  1. docker

  2. docker pull nvcr.io/nvidia/deepstream:5.1-21.02-devel       (you must download the - devel suffix here, because it includes the development sdk)

  3. Install vscode (vscode can be developed remotely directly in docker, which is very convenient. Just search vscode in Ubuntu software)

=====================docker installation=======

Install NVIDIA docker

     Before using the docker container with cuda environment, you first need to install the NVIDIA docker component

Add NVIDIA docker source

curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/ubuntu18.04/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update

Install NVIDIA docker2

     install   nvidia-docker2   Restart after   docker   bring   nvidia-docker2   take effect.

sudo apt-get install nvidia-docker2
sudo systemctl restart docker

==========   Download the deepstream image   devel version  =====

Docker container for dGPU

The container page in the NGC web portal provides instructions for pulling and running containers, as well as a description of their contents. The dGPU container is called DeepStream, and the Jetson container is called deepstream-l4t. Unlike the container in DeepStream 3.0, the dGPU DeepStream 5.1 container supports DeepStream application development within the container. It contains the same build tools and development libraries as the DeepStream 5.1 SDK. In a typical scenario, you build, execute, and debug a DeepStream application within the DeepStream container. Once your application is ready, you can use the DeepStream 5.1 container as the basic image to create your own Docker container to save your application files (binaries, libraries, models, configuration files, etc.). This is a sample fragment for creating your own Dockerfile of Docker container:

# Replace with required container type e.g. base, devel etc in the following line FROM nvcr.io/nvidia/ deepstream:5.1-21.02-<container type> COPY myapp  /root/apps/myapp # To get video driver libraries at runtime (libnvidia-encode.so/libnvcuvid.so) ENV NVIDIA_DRIVER_CAPABILITIES $NVIDIA_DRIVER_CAPABILITIES,video

This Dockerfile copies your application (from the directory mydsapp) to the container(  ) Note that you must ensure that the location of the DeepStream 5.1 image from NGC is accurate. pathname  / root/apps

The following table lists the docker container for dGPU published with DeepStream 5.1:

Docker container for dGPU

Container pull command and opening a container

====Open swap space====

If it is not enabled, cv::imshow() cannot be used

docker pull nvcr.io/nvidia/deepstream:5.1-21.02-devel
 docker run --gpus all -it -p 127.0.0.1:6666:6666 --shm-size=5g --name=deepstream5 -v /tmp/.X11-unix:/tmp/.X11-unix -v /home/sy/work:/home/sy/work -e DISPLAY=$DISPLAY -e GDK_SCALE -e GDK_DPI_SCALE -w /opt/nvidia/deepstream/deepstream-5.1 deepstream:v5.1 /bin/bash

====docker + opencv + imshow supports opencv window display===

Solution: install xserver on the host (for example, my Ubuntu 18.04) and treat the docker container as a client. In this way, the images to be displayed in the container can be displayed on the screen of the host by mounting. In short, share the screen of the host with the docker container

Detailed steps:

Step 1: install xserver on the host

    ​sudo apt install x11-xserver-utils

Step 2: modify the permissions on the host to allow all users to access the display interface

         Execute on your computer to display   xhost +  # If the following statement appears, remember to execute it every time you restart, just in case:

sy@sy:~$ xhost +
access control disabled, clients can connect from any host
sy@sy:~$ 

========Install vscode and configure the docker development environment of vscode-========

First, create a CMakelists.txt file and write the following:

cmake_minimum_required(VERSION 2.8)
project(DeepstreamApp)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPLATFORM_TEGRA")
set(CMAKE_CXX_STANDARD 14)
set(SRC_PATH /opt/nvidia/deepstream/deepstream-5.1)
set(SRC_FOLDER ${SRC_PATH}/sources/apps/sample_apps/deepstream-app)
set(SRC_INC ${SRC_PATH}/sources/apps/apps-common/includes)
set(SRC_INC2 ${SRC_PATH}/sources/includes)
set(SRC_SRC ${SRC_PATH}/sources/apps/apps-common/src)
find_package(OpenCV REQUIRED)#REQUIRED means that the package must be found. If it cannot be found, it will stop
# message(STATUS "version: ${OpenCV_VERSION}$\n")
# message(STATUS "libraries:${OpenCV_LIBS}$\n")
# message(STATUS "INCLUDE PATH:${OpenCV_INCLUDE_DIRS}$\n")
include_directories(${PROJECT_SOURCE_DIR}
${SRC_FOLDER}
${SRC_INC}
${SRC_INC2}
${SRC_SRC}
/usr/include
/usr/include/opencv
/usr/include/opencv2
/usr/local/cuda/include
/usr/include/gstreamer-1.0
/usr/include/glib-2.0
/usr/lib/x86_64-linux-gnu/glib-2.0/include
/usr/include/json-glib-1.0)
link_directories(${SRC_PATH}/lib
/usr/local/cuda/lib64
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/gstreamer-1.0)
# list(REMOVE_ITEM SRCS1 "${SRC_INC}/deepstream_osd.h")
# list(REMOVE_ITEM SRCS1 "${SRC_SRC}/deepstream_osd_bin.c")
file(GLOB SRCS2 ${PROJECT_SOURCE_DIR}/*.c ${PROJECT_SOURCE_DIR}/*.cpp ${PROJECT_SOURCE_DIR}/*.h)
#message("sources1 ${SRCS1}")
#message("sources2 ${SRCS2}")
# add_executable(deepstreamApp ${SRCS1} ${SRCS2})
add_executable(deepstreamApp ${SRCS2})
# include cuda
# target_link_libraries(deepstreamApp -lcudart -lnvdsgst_meta -lnvds_meta -lnvdsgst_helper -lnvds_utils -lnvds_msgbroker -lgstrtp-1.0 -lX11 -lm -lgstreamer-1.0 -lgstrtspserver-1.0 -lglib-2.0 -lgobject-2.0 -lgstvideo-1.0 -lnvdsgst_smartrecord -ljson-glib-1.0)
target_link_libraries(deepstreamApp ${OpenCV_LIBS} -lcudart -lnvdsgst_meta -lnvds_meta -lnvdsgst_helper -lnvds_utils -lnvds_msgbroker -lgstrtp-1.0 -lX11 -lm -lgstreamer-1.0 -lgstrtspserver-1.0 -lglib-2.0 -lgobject-2.0 -lgstvideo-1.0 -lnvdsgst_smartrecord -ljson-glib-1.0)

Then, write the following in the c_cpp_properties.json file of the C + + header file contained in vscode (this file does not know how to generate, you can baidu by yourself):

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "/opt/nvidia/deepstream/deepstream-5.1/sources/apps/sample_apps/deepstream-app",
                "/opt/nvidia/deepstream/deepstream-5.1/sources/apps/apps-common/includes",
                "/opt/nvidia/deepstream/deepstream-5.1/sources/includes",
                "/opt/nvidia/deepstream/deepstream-5.1/sources/apps/apps-common/src",
                "${workspaceFolder}/**",
                "/usr/include",
                "/usr/include/opencv",
                "/usr/include/opencv2",
                // "/usr/local/cuda/include",
                "/usr/include/gstreamer-1.0",
                "/usr/include/glib-2.0",
                "/usr/lib/x86_64-linux-gnu/glib-2.0/include",
                "/usr/include/json-glib-1.0"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

Tags: Docker OpenCV Ubuntu Visual Studio Code deepstream

Posted on Wed, 10 Nov 2021 03:19:00 -0500 by trixx