-
-
Save GowriUmesh/50b61da30ba02ad2c9a39f9660ff1fed to your computer and use it in GitHub Desktop.
Dockerfile to create images with ZED SDK and OpenCV support. This Dockerfile is to be used to build desktop images and not images for Jetson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# This is a shell script that configures the build arguements to the Dockefile | |
# and builds a Docker image with a default tag. | |
# | |
# Available versions to configure the arguements: | |
# UBUNTU_RELEASE_YEAR = 18 and 20 | |
# ZED SDK Versions = 3.0 to 3.7 (ZED SDK version <3 are too old and outdated) | |
# CUDA Versions = 10.0, 10.2, 11.0, 11.1, 11.4, 11.5 | |
# OPENCV_VERSION : Refer to change log https://github.com/opencv/opencv/wiki/ChangeLog#version455 | |
# to choose your desired version | |
#Below are th edefault values | |
UBUNTU_RELEASE_YEAR=20 #Specify the Ubunutu release year | |
ZED_SDK_MAJOR=3 # ZED SDK major version | |
ZED_SDK_MINOR=7 # ZED SDK minor version | |
CUDA_MAJOR=11 # CUDA major version | |
CUDA_MINOR=4 # CUDA minor version | |
OPENCV_VERSION=4.5.3 # OpenCV version | |
#Check for the version compatibilities | |
if [ ${UBUNTU_RELEASE_YEAR} == "18" ] ; then | |
echo "Ubuntu 18.04" | |
# Not compatible with CUDA <= 9 | |
if [ ${CUDA_MAJOR} -le "9" ] ; then | |
echo "Ubunutu 18.04 Not compatible with CUDA <= 9" | |
exit | |
fi | |
elif [ ${UBUNTU_RELEASE_YEAR} == "20" ] ; then | |
# Not compatible with CUDA <= 10 | |
if [ ${CUDA_MAJOR} -le "10" ] ; then | |
echo "Ubunutu 20.04 is not compatible with CUDA <= 10 " | |
exit | |
fi | |
else | |
echo "UBUNTU_RELEASE_YEAR! Allowed values are 18 or 20 " | |
exit | |
fi | |
if [ ${CUDA_MAJOR} -ge "11" ] ; then | |
if [ ${ZED_SDK_MINOR} -lt "2" ] ; then # CUDA 11.0 was introduced with 3.2 | |
echo "CUDA 11.0 was introduced with 3.2" | |
exit | |
fi | |
if [ ${CUDA_MINOR} -ge "1" ] ; then | |
if [ ${ZED_SDK_MINOR} -lt "3" ] ; then # CUDA 11.1 was introduced with 3.3 | |
echo "CUDA 11.1 was introduced with 3.3" | |
exit | |
fi | |
fi | |
if [ ${CUDA_MINOR} == "2" ] || [ ${CUDA_MINOR} == "3" ] || [ ${CUDA_MINOR} -ge "6" ] ; then | |
#invalid CUDA versions | |
echo "Invalid CUDA_MINOR! Allowed values : 0,1,4,5" | |
exit | |
fi | |
elif [ ${CUDA_MAJOR} == "10" ] ; then | |
if [ ${CUDA_MINOR} != "0" ] || [ ${CUDA_MINOR} != "2" ] ; then | |
echo "Invalid CUDA_MINOR! Allowed values are 0 or 2" | |
exit | |
fi | |
else | |
echo "Invalid CUDA_MAJOR! Allowed values are 10 or 11" | |
fi | |
# Default Tag based on the selected versions | |
TAG="${ZED_SDK_MAJOR}.${ZED_SDK_MINOR}-opencv-gl-devel-cuda${CUDA_MAJOR}.${CUDA_MINOR}-ubuntu${UBUNTU_RELEASE_YEAR}.04" | |
echo "Building '${TAG}'" | |
docker build --build-arg UBUNTU_RELEASE_YEAR=${UBUNTU_RELEASE_YEAR} \ | |
--build-arg ZED_SDK_MAJOR=${ZED_SDK_MAJOR} \ | |
--build-arg ZED_SDK_MINOR=${ZED_SDK_MINOR} \ | |
--build-arg OPENCV_VERSION=${OPENCV_VERSION} \ | |
--build-arg CUDA_MAJOR=${CUDA_MAJOR} \ | |
--build-arg CUDA_MINOR=${CUDA_MINOR} \ | |
-t "${TAG}" -f Dockerilfe.opencv . | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build arguments | |
ARG UBUNTU_RELEASE_YEAR | |
ARG ZED_SDK_MAJOR | |
ARG ZED_SDK_MINOR | |
ARG CUDA_MAJOR | |
ARG CUDA_MINOR | |
# Specify the parent image from which we build | |
FROM stereolabs/zed:${ZED_SDK_MAJOR}.${ZED_SDK_MINOR}-gl-devel-cuda${CUDA_MAJOR}.${CUDA_MINOR}-ubuntu${UBUNTU_RELEASE_YEAR}.04 | |
# OpenCV Version | |
ARG OPENCV_VERSION | |
# Install dependencies | |
RUN apt-get update || true && apt-get upgrade -y &&\ | |
# Install build tools, build dependencies and python | |
apt-get install --no-install-recommends -y \ | |
build-essential gcc g++ \ | |
cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev \ | |
libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev \ | |
yasm libatlas-base-dev gfortran libpq-dev \ | |
libxine2-dev libglew-dev libtiff5-dev zlib1g-dev libavutil-dev libpostproc-dev \ | |
libeigen3-dev python3-dev python3-pip python3-numpy libx11-dev tzdata \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Set Working directory | |
WORKDIR /opt | |
# Install OpenCV from Source | |
RUN git clone --depth 1 --branch ${OPENCV_VERSION} https://github.com/opencv/opencv.git && \ | |
git clone --depth 1 --branch ${OPENCV_VERSION} https://github.com/opencv/opencv_contrib.git && \ | |
cd opencv && \ | |
mkdir build && \ | |
cd build && \ | |
cmake \ | |
-D CMAKE_BUILD_TYPE=RELEASE \ | |
-D CMAKE_INSTALL_PREFIX=/usr/ \ | |
-D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages \ | |
-D WITH_V4L=ON \ | |
-D WITH_QT=OFF \ | |
-D WITH_OPENGL=ON \ | |
-D WITH_GSTREAMER=ON \ | |
-D OPENCV_GENERATE_PKGCONFIG=ON \ | |
-D OPENCV_ENABLE_NONFREE=ON \ | |
-D OPENCV_EXTRA_MODULES_PATH=/opt/opencv_contrib/modules \ | |
-D INSTALL_PYTHON_EXAMPLES=OFF \ | |
-D INSTALL_C_EXAMPLES=OFF \ | |
-D BUILD_EXAMPLES=OFF .. && \ | |
make -j"$(nproc)" && \ | |
make install | |
# ALternatively, Install from Ubuntu Repository | |
### | |
#RUN apt-get update -y || true && \ | |
# DEBIAN_FRONTEND=noninteractive apt-get install -y && \ | |
# apt-get install -y --no-install-recommends libopencv-dev && \ | |
# rm -rf /var/lib/apt/lists/* && apt autoremove && apt clean | |
### | |
WORKDIR / | |
CMD ["bash"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment