In this post, we are sharing Docker image for OpenCV 3.4.3, and the recently released OpenCV 3.4.4 and OpenCV 4.0. In addition to OpenCV, the image also has dlib and a Facial Landmark Detection example code.
Every day we receive a few emails and comments on our posts about OpenCV and Dlib installation. Even with the detailed and tested instructions, sometimes it is tough for people to get a system up and running. So, we have been thinking of providing a solution for people who have struggled with installation issues.
One way to solve this problem is to provide a Virtual Machine (VM) with all the libraries installed. A huge downside of using a VM is the large file people need to download. Sometimes it can be 10s of GBs.
A smarter and newer way to solve this problem is to provide a Docker image. Typically a Docker image size is much smaller than a VM. Our Docker image, for example, is just 1 GB in size (compressed size). In addition, it starts much faster than a VM and typically runs applications much faster compared to a VM. Docker is just one of those minimal things that can make your life exceedingly simple.
Docker: have a Ubuntu development machine within seconds, from Windows or Mac. Much faster than any Virtual Machine, Docker allows you to run a Ubuntu image and gain interactive access to its shell, so you can have all your dependencies in an isolated Linux environment and develop from your favourite IDE, anywhere. Saving state with Docker Is it possible to 'suspend' a Docker container and resume later, maybe even on a different server. For example, with a VM, you can suspend the VM, move the image to a different machine, and resume.
Also, as we’ll see, the same docker image can be used on Windows, Ubuntu and MacOS. If you are stuck with OpenCV installation or if you want to try out the new OpenCV-3.4.4 and OpenCV-4.0 ( released on 20th November 2018 ), without actually installing it on your system, this docker image is the perfect match for you.
This post is split into five sections
- Section 1: How to install Docker on Linux, MacOS and Windows.
- Section 2: How to use Docker image for OpenCV. This image also comes with dlib pre-installed.
- Section 3: How to run Facial Landmark Detection demo code on Docker Image
- Section 4: How to make changes to a Docker image.
1. Docker Installation
In this section, we will learn how to install Docker on Ubuntu, MacOS, and Windows.
1.1 Installing Docker on Ubuntu
- To install docker on Ubuntu 16.04, first add the GPG key for the official Docker repository to the system:
- Add the Docker repository to APT sources:
- Next, update the package database with the Docker packages from the newly added repo:
- Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:
- You should see output similar to the following:
- Finally, install Docker:
1.2 Installing on MacOS
- To install Docker on MacOS desktop, first go to the Docker Store and download Docker Community Edition for Mac.
- Double-click Docker.dmg to open the installer, then drag Moby the whale to the Applications folder.
- Double-click Docker.app in the Applications folder to start Docker.
- You are prompted to authorise Docker.app with your system password after you launch it. Privileged access is needed to install networking components and links to the Docker apps.
The whale in the top status bar indicates that Docker is running, and accessible from a terminal.
1.3 Installing Docker Toolbox in Windows 7 or above
- Download and install Docker Toolbox for Windows. The installer adds Docker Toolbox, VirtualBox, and Kitematic to your Applications folder.
- On your Desktop, find the Docker QuickStart Terminal icon.
- Double click the Docker QuickStart icon to launch a pre-configured Docker Toolbox terminal.
- Press enter and the installation will be automatically started. Once done, the file will be present in
usersusername.dockermachinecacheboot2docker.iso.
- If the system displays a User Account Control prompt to allow VirtualBox to make changes to your computer, choose Yes.
The terminal does several things to set up Docker Toolbox for you. When it is done, the terminal displays the $ prompt.
2 Install Docker OpenCV Image
The docker image has been updated to enable X11-Forwarding and now also contain an example to test installation. Use docker pull to get the latest image.
To use the docker image, use the following instructions:
Once, the image is downloaded, we can start it using the following command
Let’s take a moment to examine this command in detail:
- –device=/dev/video0:/dev/video0 allows use of webcam
- -v /tmp/.X11-unix:/tmp/.X11-unix helps in X11 forwarding so that we can use functions like cv::imshow.
- -e is used to pass an environment variable.
- -it starts an interactive session
- -p sets up a port forward. This flag maps the container’s port to a port on the host system.
- /bin/bash runs .bashrc file on startup
The image has OpenCV 3.4.3 installed in /usr/local, OpenCV 3.4.4 in ~/installation/OpenCV-3.4.4 and OpenCV 4.0.0 in ~/installation/OpenCV-master.
To use Python environments:
For OpenCV 3.4.3,
Once you are in the iPython prompt, do
To deactivate the virtual environment use Download ebook manajemen pemasaran kotler.
Similarly for OpenCV 3.4.4 and OpenCV 4.0.0,
Once you are in the iPython prompt, do
To deactivate the virtual environment type
Once you are in the iPython prompt, do
3 Run Facial Landmark Detection on Docker Image
To test the installation of OpenCV and dlib on the docker image, we have provided a Facial Landmark detection example that you can try out.
- First, we make sure that we have the latest docker image.
- Next, we run the docker image as specified in the earlier sections.
- Once the docker container is created and is running, you will find 3 folders in /root/ – common, demo and installation. The demo folder contains C++ and Python version of the Facial Landmark Detection code.
- To run the Python script, follow the steps given below. The instructions are for OpenCV-4.0.0. For OpenCV-3.4.3 and OpenCV-3.4.4 just change the environment as discussed earlier.
- To run the C++ code, follow the steps given below:
You will find 3 folders, one for each OpenCV version installed. The CMakeLists.txt file present in the folders can be used as a reference for building codes for that particular OpenCV version.
4 How to commit changes to Docker Image
By default, whatever changes you make in your docker image are NOT saved.
To commit changes made to the docker image, we need to follow the steps below. We will refer to the image of the terminal below as an example
- Find the Container ID: The easiest way to find it out is to note the text following [email protected] in your docker container. For example, in the image above, the docker container ID is 56a07cf4614c. Also, note that Container ID will vary every time you use docker run to create a new container.
- Make a change: In the example above, we create a simple file HelloUser.sh that outputs some text when run from the command line.
- Exit: Once the changes have been made, we need to exit the container using exit command.
- Commit changes: Finally, to commit the changes made to the docker image use the following command
In our example, we use
- Check image: You want to make sure the committed docker image shows up when you run the following command
- Use image: Next time when you want to use this docker image, just use the following command:
In our specific example, we use
The discography of Clutch, an American rock band, consists of twelve studio albums, five live albums, three compilation albums, five extended plays, ten singles, and two video albums. Clutch was formed in 1991 by vocalist Neil Fallon, guitarist Tim Sult, bassist Dan Maines and drummer Jean-Paul Gaster. The group debuted with Pitchfork, an EP released in October that same year. Clutch is an American Rock band that got its start in the early 1990's in the Maryland-Washington, DC area. Members include Neil Fallon (vocals), Tim Sult (lead guitar), Dan Maines (bass), and Jean Paul Gaster (drums).
Hope you have fun hacking with Docker! 🙂 If you have any queries, comment below and we will get back to you as soon as possible.
Subscribe & Download Code
If you liked this article and would like to download code (C++ and Python) and example images used in other posts of this blog, please subscribe to our newsletter. You will also receive a free Computer Vision Resource Guide. In our newsletter, we share OpenCV tutorials and examples written in C++/Python, and Computer Vision and Machine Learning algorithms and news.
References
- Docker for Data Science: Building Scalable and Extensible Data Infrastructure Around the Jupyter Notebook Server by Joshua Cook
A collection of docker online resources.
中文版本链接
- Docker
- Underlying Techniques
- Various Projects
- Usage
Books
- Docker in Action (Early Access Edition)
- Docker in Practice (Early Access Edition)
- Docker Cookbook by Neependra Khare (@neependra)
- Docker Cookbook by Sébastien Goasguen (@sebgoa) (Early Access Edition)
- Using Docker (Early Access Edition)
Websites
Documents
Archives
Community Blogs
Personal Blogs
Videos
Core
OS
- Coreos (Linux for Massive Server Deployments)
- Atomic (A platform optimized for Linux containers)
- Rancheio (Simple, elegant tools for managing Docker in production)
- Snappy (A new, transactionally updated Ubuntu for clouds and devices)
- ClearLinux (The Clear Linux™ Project for Intel® Architecture is a project that is building a Linux OS distribution for various cloud use cases)
- Mirage OS (Unikernel)
Virtual Machine
- boot2docker (Lightweight Linux for Docker)
- dvm (An on demand Docker virtual machine)
Competitors
- rocket (App Container runtime)
- dockerlite (Lightweight virtualization system based on LXC and BTRFS)
- lmctfy (lmctfy is the open source version of Google’s container stack, which provides Linux application containers.)
- Hyper (Hyper = Hypervisor + Kernel + Docker Image)
- bocker (Docker implemented in around 100 lines of bash)
- lxd (Daemon based on liblxc offering a REST API to manage containers )
Management Tools
- kubernetes (Container Cluster Manager)
- shipyard (Composable Docker Management)
- swarm (A Docker-native clustering system)
- citadel (A toolkit for building a distributed docker cluster)
- docker-cluster (Cluster support for Docker, using the remote API)
- compose (Define and run complex applications using Docker)
- shutit (Complex and Dynamic Docker Builds Made Simple)
- maestro (Container orchestration for Docker environments)
- decking (A Docker helper to create, manage and run clusters of containers)
- flocker (Easily manage Docker containers & their data)
- serf (Service orchestration and management tool)
- marathon (Deploy and manage containers (including Docker) on top of Apache Mesos at scale)
- gaudi (Gaudi allows to share multi-component applications, based on Docker, Go, and YAML)
- panamax (Docker management for humans)
- clocker (Brooklyn managed Docker containers)
- [fleet] (https://github.com/coreos/fleet) (A Distributed init System)
- Meteor(Clustering solution for Meteor with load balancing and service discovery)
- helios (Docker container orchestration platform)
- maestro-ng (Orchestration of Docker-based, multi-host environments)
- shipper (Fabric for docker containers)
- origin (OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes)
- autodock (The docker container automation tool.)
- blockade (Docker-based utility for testing network failures and partitions in distributed applications,docs)
- rancher (A Platform for Operating Docker in Production.rancher.com)
- rocker-compose (Docker composition tool with idempotency features for deploying apps composed of multiple containers.)
- chronos(Fault tolerant job scheduler for Mesos which handles dependencies and ISO8601 based schedules)
Paas Platforms
- flynn (A next generation open source platform as a service)
- deis (Your PaaS. Your Rules)
- peas (Docker and Ruby based PaaS)
- dawn (Docker-based PaaS in Ruby)
- octohost(Simple web focused Dockerfile based PaaS server)
- dokku (Docker powered mini-Heroku in around 100 lines of Bash)
- paz (A pluggable in-house service platform with a PaaS-like workflow, built on Docker, CoreOS, Etcd and Fleet)
- armada (Complete solution for development, deployment, configuration and discovery of microservices)
- rainbond (Serverless PaaS , A new generation of easy-to-use cloud management platforms based on kubernetes.)
Caas Platforms
Integration Projects
- openstack-docker (Nova driver and Glance backend to use Docker inside OpenStack)
- deimos (Mesos containerizer hooks for Docker)
- garether-docker (Puppet module for managing docker)
- systemd-docker (Wrapper for 'docker run' to handle systemd quirks)
- docker-ansible (Ansible module for Docker)
Monitoring
- seagull (Friendly Web UI to monitor docker daemon)
- dockerana (Docker Monitoring with support for Grafana and Graphite)
- docker-mon(Console-based Docker monitoring)
- cadvisor (Analyzes resource usage and performance characteristics of running containers)
- Prometheus (The Prometheus monitoring system and time series database,see the docker exporter)
- ctop (Top-like interface for container metrics https://bcicen.github.io/ctop/)
- NexClipper - Simple web UI for container monitoring by @Nexcloud
Networking
- weave (The Docker Network)
- wormhole (A smart proxy to connect docker containers.)
- flannel (flannel is an etcd backed network fabric for containers)
- calico-docker(Docker version of Project Calico,Calico can provide networking in a Docker environment)
- libnetwork (networking for containers)
Continuous Integration
- drone (A Continuous Integration platform built on Docker)
Development And Deployment
- tug (Docker development workflow)
- vagga(Vagga is a tool to create development environments)
- longshoreman (Automated deployment with Docker)
- centurion (A mass deployment tool for Docker fleets)
- shutit (Complex and Dynamic Docker Builds Made Simple)
- dockership (dead simple docker deploy tool)
- devstep (Development environments powered by Docker and buildpacks)
- docker-devenv (Docker based development environment)
- dexec (Command line interface for running code with Docker Exec images)
Logging
- logspout (Log routing for Docker container logs)
- logjam (a log shipping tool)
Service Discovery
- skydock (based on DNS)
- Consul (Consul is a tool for service discovery, monitoring and configuration)
- registrator(Service registry bridge for Docker with pluggable adapters)
- etcd (A highly-available key value store for shared configuration and service discovery)
- docker-grand-ambassador ( fully dynamic docker link ambassador)
- confd (Manage local application configuration files using templates and data from etcd or consul)
- ambassadord (Magic Docker ambassador)
- logcabin (LogCabin is a distributed storage system built on Raft that provides a small amount of highly replicated, consistent storage)
Private Registry
- docket (Custom docker registry that allows for lightning fast deploys through bittorrent)
- docker-registry (Registry server for Docker (hosting/delivering of repositories and images))
- wharf(ContainerOps Open Source Platform)
- distribution (The Docker toolset to pack, ship, store, and deliver content)
- [dogestry] (https://github.com/blake-education/dogestry) (simple docker image storage on s3)
- docker-private-registry (Private Docker Registry)
- speedy (a distributed docker image storage)
UI Tools
- dockerboard (Simple dashboards, visualizations, managements for your dockers)
- Kitematic (Now part of the Docker Toolbox. Available for Mac OS X 10.8+ and Windows 7+ (64-bit) )
- dockerui (A web interface for docker)
- docker-registry-web (A web UI for easy private/local Docker Registry integration)
- Portus (Authorization service and frontend for Docker registry v2)
- panamax-ui (The Web GUI for Panamax)
- seagull (Friendly Web UI to monitor docker daemon)
- docker-swarm-visualizer(A visualizer for Docker Swarm using the Docker Remote API, Node.JS, and D3)
- portainer ( Simple management ui for docker )
- Swarmpit ( Lightweight Docker Swarm management UI )
- Swirl (A web management tool for Docker, focusing on Swarm cluster)
Storage
- pfs (A git-like distributed file system for a dockerized world)
Volumes
- docker-volumes (Docker Volume Manager)
Security
- subuser (Run programs in linux with selectively restricted permissions)
- TUF (Like the S in HTTPS, a plug-and-play library for securing a software updater)
- container-compliance(Assessing compliance of a container)
Applications
- ferry (define, run, and deploy big data applications on AWS, OpenStack, and your local machine using Docker,ferry.opencore.io)
- codecube (Docker-powered runnable code snippets)
- DUnit (Test code against multiple versions of PHP with the help of docker)
- PHP Stack (Docker- and Shipyard-managed PHP development stack: Nginx, MySQL, MongoDB, PHP-FPM, HHVM, Memcached, Redis, and Elasticsearch. Includes an optional Vagrant-managed CoreOS proxy box at your leisure.)
- Django Demo (Demo Django App using Docker)
- dnt (Docker Node Tester)
- dockermail (A secure, minimal-configuration mail server in a docker container.)
- docker-rpm-builder (Build native RPM packages by leveraging docker capabilities)
- tmpnb (Creates temporary Jupyter Notebook servers using Docker containers)
- open-ocr (Run your own OCR-as-a-Service using Tesseract and Docker)
- dray (An engine for managing the execution of container-based workflows)
- kolla (Deploying OpenStack using Kubernetes and Docker)
- docker-desktop (Docker Desktop enables you to create virtual desktops that can be accessed remotely. It comes with Firefox and Libreoffice already installed)
- dockercraft (Docker + Minecraft = Dockercraft)
Images And Dockerfiles
- dockly (DSL and Gem for building ready-to-launch Docker images)
- baseimage-docker (A minimal Ubuntu base image modified for Docker-friendlines)
- busybox (Busybox for Stackbrew)
- busybox (Busybox container with glibc+opkg)
- passenger-docker (Docker base images for Ruby, Python, Node.js and Meteor web apps)
- Dockerfiles(Collection of Dockerfiles)
- docker-desktop (create virtual desktops that can be accessed remotely)
- StealthBox(Share your favorite content remotely without spoiling your home network)
- Machine Learning (Get up and running with machine learning using Docker)
- Gitlab (Dockerized gitlab web server)
- Discourse (A Docker image for Discourse)
- OpenVPN (Recipe to build an OpenVPN image for Docker)
- Wordpress+nginx (A Dockerfile that installs the latest wordpress, nginx and php-fpm.another wordpress image) / another one wordpress
- Nignx-Proxy (Automated nginx proxy for Docker containers using docker-gen)
- docker-squash (Squash docker images to make them smaller)
- Mysql (Docker image to run an out-of-the-box MySQL server)
- CentOS-Dockerfiles (Dockerfiles for various common implementations)
- Redmine (Dockerized redmine app server)
- Spark (Dockerfiles and scripts for Spark and Shark Docker images)
- docker-grafana-graphite (Docker image with StatsD, Graphite, Grafana and a Kamon Dashboard)
- Elasticsearch (ElasticSearch Dockerfile for trusted automated Docker builds)
- docker-alpine (Docker image based on Alpine Linux will help you win at minimalism)
- Hadoop (Hadoop docker image)
- R (R configurations for Docker)
- ASP.NET (Docker image for ASP.NET 5.)
- nmpjs (Docker image for a private npmjs repository)
- Jenkins (Builds a Docker image for Jenkins)
- Postgres (Docker Official Image packaging for Postgres)
- Logstash (Docker image for Logstash 1.4 )
- Harbor (An enterprise-class container registry server based on Docker Distribution)
Containers
- dockize (Utility to simplify running applications in docker containers)
- Supervisor (A Process Control System)
- CFEngine (Process management)
- docker-gen (Generate files from docker container meta-data)
- tini (A tiny but valid
init for containers) - S6 (s6 is a small suite of programs for UNIX, designed to allow process supervision)
Extensions
- powerstrip (A tool for prototyping Docker extensions)
API Client
- docker-py (Python)
- docker-api (Ruby)
- dockernode (Node.js)
- go-dockerclient (Golang)
- docker-php (PHP)
- dockerclient (Golang)
- docker-java (Java)
Others
- dockersh (A shell which places users into individual docker containers)
- buildstep (Buildstep uses Docker and Buildpacks to build applications like Heroku)
- dind(Docker in Docker)
- building (Build a Docker container for any app using Heroku Buildpacks)
- torrent-docker (realtime boot of remote docker images using bittorrent)
- docker-backup (Tool for backing up docker volume / data containers)
- dockerception (Docker building dockers - keeping them small)
- docker-gc (Docker garbage collection of containers and images)
- habitus(A Build Flow Tool for Docker)
- ofelia (A docker job scheduler (aka. crontab for docker))
General
- Docker and Go: why did we decide to write Docker in Go? ( pdf slide)
Docker
About Images
About Storage
About Volumes
Dockerfiles
About Containers
About Security
Resource Management
About Networking
About Monitoring

About Private Registry
API
Performance
Process Management
Think Deeply
Rocket
Underlying Techniques
LXC
- Linux Containers (from archwiki)
Cgroups
- cgroups (from kernel.org)
- Cgroups (from archwiki)
Systemd
- The systemd for Administrators Blog Series (great series,check the index in here)
- Getting Started with systemd (from coreos)
- Systemd (from archwiki)
- Docker without Docker (slide)
Namespaces
- Introduction to Linux namespaces – Part 1: UTS / part2 /part3 / part4 /part5
Various Projects
Compose
Swarm
- Intro to Docker Swarm: Part 1 - Overview / Part 2 - Configuration Options and Requirements / Part 3 - Example Swarm SOA / Part 4 - Demo
- Running a Distributed Docker Swarm on AWS (Mar 9, 2016)
- Toward a Production-Ready Docker Swarm Cluster with Consul (Mar 2, 2016)
Mesosphere
- Continuous Delivery with Docker on Mesos in less than a minute – Part 1 / part2
Kubernetes
Openstack
Azure
Other Projects
- Process Management with CFEngine (CFEngine)
- Introducing flannel: An etcd backed overlay network for containers (flannel)
- Tiny docker operating system (Boot2Docker,RancherOS)
- Deploying Docker applications on YARN via Slider (slide)(YARN)
Usage
Apps
GUI
Service Discovery With Docker
Development And Deployment And Test
- Docker in Action - Development to Delivery / part2 / part3
Production
- [Intro to Docker ..and how we use it at writeLaTe