Opencv on l4t-base container

I am trying to create a Dockerfile on jetson with l4t-base and create a new image with opencv but when i try to build an image I encounter a linking problem and I can only create a docker when I change the command from RUN to CMD, but then it builds every time, which is a problem.

I am trying to build it using this:
RUN curl -L https://github.com/opencv/opencv/archive/4.1.0.zip -o opencv-4.1.0.zip
RUN curl -L https://github.com/opencv/opencv_contrib/archive/4.1.0.zip -o opencv_contrib-4.1.0.zip
RUN unzip opencv-4.1.0.zip && unzip opencv_contrib-4.1.0.zip
RUN cd opencv-4.1.0/ && mkdir release && cd release/ && cmake -D WITH_CUDA=ON
-D OPENCV_EXTRA_MODULES_PATH=…/…/opencv_contrib-4.1.0/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 CMAKE_INSTALL_PREFIX=/usr/local …

Vladimir,

Any luck getting linking to work in such a way that result of the step was cached by docker? I’m running into a similar issue.

Thanks,

  • Harris

Here is a script to build OpenCV in docker, along with a sample Dockerfile. You should be able to just replace the FROM line in the Dockerfile with a deepstream base image (edit: see post below for the correct base image).

If you’re still on JetPack 4.3 you can use a tag here here
like mdegans/tegra-opencv:jp-r32.3.1-cv-4.3.0 (and apt install deepstream-4.0

Otherwise latest always will target the latest JetPack and latest OpenCV.

Hi

I’m trying to use you suggested method of incorporating opencv into the deepstream image (on an xavier agx, l4t R32.4.3). I’ve therefore changed the Dockerfile to contain:

FROM nvcr.io/nvidia/deepstream-l4t:5.0-dp-20.04-base

### build argumements ###
# change these here or with --build-arg FOO="BAR" at build time
ARG OPENCV_VERSION="4.3.0"
ARG OPENCV_DO_TEST="FALSE"
# note: 8 jobs will fail on Nano. Try 1 instead.
ARG OPENCV_BUILD_JOBS="4"
# required for apt-get -y to work properly:
ARG DEBIAN_FRONTEND=noninteractive

WORKDIR /usr/local/src/build_opencv

COPY build_opencv.sh .

RUN /bin/bash build_opencv.sh

However I receive the following error when I run

sudo docker build --tag deepstream_opencv:1.0

:

+ mv /etc/apt/sources.list.d/nvidia-l4t-apt-source.list /etc/apt/    
mv: cannot stat '/etc/apt/sources.list.d/nvidia-l4t-apt-source.list': No such file or directory

It seems that the deepstream image does not have this file. Commenting out the lines where it moves the file from and back to /etc/apt/sources.list.d then leads to the following:

E: Unable to locate package cuda-compiler-10-2
E: Unable to locate package cuda-minimal-build-10-2
E: Unable to locate package cuda-libraries-dev-10-2
E: Unable to locate package libcudnn8-dev

Please help me!

Many thanks

@jimwormold
The issue is that official Nvidia images do not currently have Nvidia’s apt sources enabled and I didn’t think about that when writing the above post… Here is a patched deepstream image and dockerfile you can use to build your own from a deepstream-l4t base:

https://hub.docker.com/r/mdegans/deepstream

Let me know if …

FROM registry.hub.docker.com/mdegans/deepstream:aarch64-samples
...

… works for you or not (i may have to adjust the script). I just update it for 4.4GA but haven’t tested building on top of this DeepStream base image.

Thanks ever so much - looks like it’s working so far. I’ll update when complete.

Yes I can confirm that it works, as long as I use opencv master rather than 4.3 tag as indicated here: Jetpack 4.4 Broke one of my programs