August's Box

Docker+Ubuntu+jpeg-turbo编译opencv3

利用docker构建标准的编译环境

install docker

docker安装很简单,直接官网下载安装即可。

pull ubuntu14.04 image

$ docker pull ubuntu:14.04

run container

$ docker run --rm -it -v $PWD:/build ubuntu:14.04

install

install build-essential

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential

install libjpeg-turbo-1.5.1

$ wget https://launchpad.net/ubuntu/+archive/primary/+files/libjpeg-turbo_1.5.1.orig.tar.gz
$ tar xvf libjpeg-turbo_1.5.1.orig.tar.gz
$ cd libjpeg-turbo-1.5.1/
$ sudo apt-get install nasm
$ sudo apt-get install dh-autoreconf
$ autoreconf -fiv
$ mkdir build
$ cd build
$ sh ../configure --prefix=/usr/libjpeg-turbo --mandir=/usr/share/man --with-jpeg8 --enable-static --docdir=/usr/share/doc/libjpeg-turbo-1.5.1

# 修改Makefile,把CC: gcc改成CC: gcc -fPIC
# "-fPIC" which was an abbreviation for Position Independent Code, and this had to be passed to create library code objects, without that flag, code that is specific to the source would be used, and then the library would fail.
vi Makefile  => CC: gcc  ->  CC: gcc -fPIC

$ sudo make
# test:
    $ make test
# install:
    $ make install

install opencv

$ wget https://github.com/opencv/opencv/archive/3.2.0.zip
$ mkdir build
$ cd build

# Dependence:
# install cmake
$ wget https://cmake.org/files/v3.8/cmake-3.8.1.tar.gz
$ tar xf cmake-3.8.1.tar.gz
$ cd cmake-3.8.1
$ ./configure
$ make
$ sudo apt-get install checkinstall
$ sudo checkinstall
$ sudo make install
# install others
$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_EXAMPLES=ON -DWITH_JPEG=ON -DBUILD_JPEG=OFF -DJPEG_INCLUDE_DIR=/usr/libjpeg-turbo/include -DJPEG_LIBRARY=/usr/libjpeg-turbo/lib/libjpeg.a ..
#(中间出现ippicv相关包下载hash unmatch error,重新下载包,替换相应目录)
$ sudo make
$ sudo make install

save image

docker commit Container_ID new_image:tag
docker save new_image:tag > new_iamge.tar
新的image在其他docker机器上load即可

参考

  1. linuxfromscratch-libjpeg-turbo
  2. linuxfromscratch-opencv3
  3. Raspbian + OpenCV + libjpeg-turbo
  4. openCV 3.1.0 optimized for Raspberry Pi, with libjpeg-turbo 1.5.0 and NEON SIMD support