After publishing this post some time ago which was a tutorial on how to create a Computer Vision Docker image using OpenCV and TensorFlow, I got many questions from people about the issues they’re facing when they try to use it. If you think something of a similar nature happened to you, then this post is meant for you.
First, the image from that tutorial was built on top of an official TensorFlow Docker image, so all the issues in that image are, unfortunately, part of my image too. There’s no way around it. The other thing is, the order in which things are installed matters and trying to go back and figuring everything out (the issues) is just gonna take a long time.
So, without further ado, here is a complete Dockerfile, which will yield a Computer Vision Docker image you can use for studying and experimenting and so on. Hopefully it will also help you avoid all the issues from the previous post:
FROM ubuntu:20.04 RUN apt-get update RUN apt-get upgrade -y # Workaround for an installation issue with Ubuntu 20.04 RUN DEBIAN_FRONTEND="noninteractive" apt-get install tzdata -y RUN apt-get install wget curl build-essential cmake gcc g++ git python3 python3-pip -y RUN pip3 install --upgrade pip RUN pip3 install tensorflow RUN pip3 install tensorflow_datasets RUN pip3 install sklearn RUN pip3 install pandas RUN pip3 install jupyterlab RUN pip3 install matplotlib # Install OpenCV RUN apt-get -y install build-essential checkinstall cmake pkg-config yasm RUN apt-get -y install git gfortran RUN apt-get -y install libjpeg8-dev libpng-dev RUN apt-get -y install software-properties-common RUN add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" RUN apt-get -y update RUN apt-get -y install libjasper1 RUN apt-get -y install libtiff-dev RUN apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev RUN apt-get -y install libxine2-dev libv4l-dev RUN cd /usr/include/linux && ln -s -f ../libv4l1-videodev.h videodev.h RUN apt-get -y install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev RUN apt-get -y install libgtk2.0-dev libtbb-dev qt5-default RUN apt-get -y install libatlas-base-dev RUN apt-get -y install libfaac-dev libmp3lame-dev libtheora-dev RUN apt-get -y install libvorbis-dev libxvidcore-dev RUN apt-get -y install libopencore-amrnb-dev libopencore-amrwb-dev RUN apt-get -y install libavresample-dev RUN apt-get -y install x264 v4l-utils RUN apt-get install libjpeg-dev libopenexr-dev libwebp-dev -y RUN apt-get install ffmpeg -y RUN \ cd / \ &&\ git clone https://github.com/opencv/opencv.git --single-branch 4.4.0\ &&\ mv 4.4.0 opencv\ &&\ cd opencv\ &&\ mkdir build\ &&\ cd build\ &&\ cmake \ -D CMAKE_BUILD_TYPE=RELEASE \ -D BUILD_TESTS=OFF \ -D BUILD_PERF_TESTS=OFF \ -D BUILD_opencv_python_tests=OFF \ -D WITH_FFMPEG=ON \ -D WITH_TBB=ON \ -D WITH_V4L=ON \ -D WITH_QT=ON \ -D WITH_OPENGL=ON \ -D WITH_GSTREAMER=ON \ ..\ &&\ make\ &&\ make install ENTRYPOINT python3 -m jupyter notebook --ip=0.0.0.0 --port=5000 --allow-root
Note that this one is based on the latest versions of everything (TensorFlow, OpenCV etc.) so make sure your notebooks are compatible with it.
Also note that you have to have publish port 5000 for the image to work.
Good luck and post your questions below if you have any.