Skip to content

Commit 113b2df

Browse files
committed
update dockerfile with gdal python bindings fix. and minor updates to NDVI.sh
1 parent 02d8225 commit 113b2df

File tree

2 files changed

+82
-52
lines changed

2 files changed

+82
-52
lines changed

Dockerfile

Lines changed: 67 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
FROM ubuntu:16.04
22
MAINTAINER glw <https://github.com/glw/docker-python3-opencv>
33

4-
# Thanks to Josip Janzic <josip.janzic@gmail.com> for Opencv installation Dockerfile
4+
# Thanks to Josip Janzic <josip.janzic@gmail.com> for Opencv installation and Cayetano Benavent <cayetano.benavent@geographica.gs> for the GDAL installation
5+
6+
ENV ROOTDIR /usr/local/
7+
ENV OPENCV_VERSION="3.4.1"
8+
ENV GDAL_VERSION="2.2.4"
59

6-
RUN apt-get update && apt-get install -y software-properties-common python-software-properties
7-
RUN add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
810
RUN apt-get update && \
9-
apt-get install -y \
11+
apt-get install -y --no-install-recommends \
1012
build-essential \
1113
cmake \
1214
g++ \
1315
python3 \
1416
python3-dev \
1517
git \
16-
wget \
17-
unzip \
1818
yasm \
1919
pkg-config \
2020
libswscale-dev \
@@ -30,57 +30,76 @@ RUN apt-get update && \
3030
libexiv2-dev \
3131
libboost-python1.58.0 \
3232
libboost-python-dev \
33-
python-all-dev \
34-
gdal-bin=2.1.3+dfsg-1~xenial2 \
35-
libgdal-dev=2.1.3+dfsg-1~xenial2 \
36-
python3-gdal=2.1.3+dfsg-1~xenial2 \
37-
&& \
33+
python-all-dev
34+
35+
WORKDIR $ROOTDIR/
3836

39-
wget https://bootstrap.pypa.io/get-pip.py && \
40-
python3 get-pip.py && \
41-
rm get-pip.py \
42-
&& \
4337

44-
pip --no-cache-dir install \
45-
numpy \
46-
py3exiv2
4738

48-
WORKDIR /
49-
ENV OPENCV_VERSION="3.4.1"
50-
RUN wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip \
51-
&& unzip ${OPENCV_VERSION}.zip \
52-
&& mkdir /opencv-${OPENCV_VERSION}/cmake_binary \
53-
&& cd /opencv-${OPENCV_VERSION}/cmake_binary \
54-
&& cmake -DBUILD_TIFF=ON \
55-
-DBUILD_opencv_java=OFF \
56-
-DWITH_CUDA=OFF \
57-
-DENABLE_AVX=ON \
58-
-DWITH_OPENGL=ON \
59-
-DWITH_OPENCL=ON \
60-
-DWITH_IPP=ON \
61-
-DWITH_TBB=ON \
62-
-DWITH_EIGEN=ON \
63-
-DWITH_V4L=ON \
64-
-DBUILD_TESTS=OFF \
65-
-DBUILD_PERF_TESTS=OFF \
66-
-DCMAKE_BUILD_TYPE=RELEASE \
67-
-DCMAKE_INSTALL_PREFIX=$(python3.5 -c "import sys; print(sys.prefix)") \
68-
-DPYTHON_EXECUTABLE=$(which python3.5) \
69-
-DPYTHON_INCLUDE_DIR=$(python3.5 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
70-
-DPYTHON_PACKAGES_PATH=$(python3.5 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") .. \
71-
&& make install \
72-
&& rm /${OPENCV_VERSION}.zip \
73-
&& rm -r /opencv-${OPENCV_VERSION}
39+
# install gdal 2.2.4
40+
WORKDIR /$ROOTDIR/src
41+
ADD http://download.osgeo.org/gdal/2.2.4/gdal-${GDAL_VERSION}.tar.xz /$ROOTDIR/src
42+
RUN tar -xf gdal-${GDAL_VERSION}.tar.xz \
43+
&& cd gdal-${GDAL_VERSION} \
44+
&& ./configure --with-python --with-geos --with-geotiff --with-jpeg \
45+
&& make && make install && ldconfig \
46+
&& apt-get update -y \
47+
&& apt-get remove -y --purge build-essential
48+
#&& cd $ROOTDIR && cd src/gdal-${GDAL_VERSION}/swig/python \
49+
#&& python3 setup.py build \
50+
#&& python3 setup.py install \
51+
#&& cd $ROOTDIR && rm -Rf src/gdal*
52+
53+
# install pip
54+
WORKDIR /$ROOTDIR
55+
ADD https://bootstrap.pypa.io/get-pip.py /$ROOTDIR
56+
RUN cd $ROOTDIR \
57+
&& python3 get-pip.py \
58+
&& rm get-pip.py \
59+
&& pip3 --no-cache-dir install \
60+
numpy \
61+
py3exiv2 \
62+
GDAL==${GDAL_VERSION}
63+
64+
65+
# install opencv
66+
WORKDIR /$ROOTDIR/src
67+
ADD https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.tar.gz /$ROOTDIR/src
68+
RUN tar -xzf ${OPENCV_VERSION}.tar.gz \
69+
&& cd opencv-${OPENCV_VERSION} \
70+
&& mkdir cmake_binary \
71+
&& cd cmake_binary \
72+
&& cmake -DBUILD_TIFF=ON \
73+
-DBUILD_opencv_java=OFF \
74+
-DWITH_CUDA=OFF \
75+
-DENABLE_AVX=ON \
76+
-DWITH_OPENGL=ON \
77+
-DWITH_OPENCL=ON \
78+
-DWITH_IPP=ON \
79+
-DWITH_TBB=ON \
80+
-DWITH_EIGEN=ON \
81+
-DWITH_V4L=ON \
82+
-DBUILD_TESTS=OFF \
83+
-DBUILD_PERF_TESTS=OFF \
84+
-DCMAKE_BUILD_TYPE=RELEASE \
85+
-DCMAKE_INSTALL_PREFIX=$(python3.5 -c "import sys; print(sys.prefix)") \
86+
-DPYTHON_EXECUTABLE=$(which python3.5) \
87+
-DPYTHON_INCLUDE_DIR=$(python3.5 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
88+
-DPYTHON_PACKAGES_PATH=$(python3.5 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") .. \
89+
&& make install \
90+
&& cd $ROOTDIR/src \
91+
&& rm ${OPENCV_VERSION}.tar.gz \
92+
&& rm -rf opencv-${OPENCV_VERSION}/
7493

7594

7695
# Clean up APT when done.
7796
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
7897

98+
# set python3 as default python
99+
RUN update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 \
100+
&& update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
101+
79102
# Externally accessible data is by default put in /data
80103
WORKDIR /data
81104

82-
# dont really need COPY command since the volume command puts it in your containers directory
83-
#copy relevant files for converting tif image to jpg and NDVI calculation
84-
#COPY NDVI-calc.sh tiff_2_jpg_convert.py write_colormap_file.py /data/
85-
86105
CMD ["/bin/bash"]

NDVI-calc.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
# gets read from a database, hardwired here
22
NDVI_COLORMAP="006600 008800 00BB00 00FF00 CCFF00 FFFF00 FFCC00 FF8800 FF0000 EE0000 DD0000 CC0000 BB0000 AA0000 990000 880000 770000"
33

4-
NIR_INPUT=nir_input.tif
4+
NIR_INPUT=IMG_171026_183605_0000_NIR.jpg
55
NIR_OUTPUT=nir_output.tif
66

7-
RED_INPUT=red_input.tif
7+
RED_INPUT=IMG_171026_183605_0000_RED.jpg
88
RED_OUTPUT=red_output.tif
99

1010
NDVI_IMAGE=new_ndvi.tif
1111
NDVI_COLOR=ndvi_color.tif
1212

1313
python write_colormap_file.py "$NDVI_COLORMAP" custom.txt
1414

15-
15+
echo "NIR input: $NIR_INPUT"
1616
echo "Creating NIR part of the NDVI color image for red filtered image..."
17+
1718
gdal_calc.py --calc="A" --A_band=1 --type=Float32 -A $NIR_INPUT --outfile $NIR_OUTPUT --NoDataValue=1.001 --overwrite
1819

20+
echo "NIR output: $NIR_OUTPUT"
1921

22+
23+
echo "Red input: $RED_INPUT"
2024
echo "Creating VIS part of the NDVI color image for red filtered image..."
25+
2126
gdal_calc.py --calc="A" --A_band=1 --type=Float32 -A $RED_INPUT --outfile $RED_OUTPUT --NoDataValue=1.001 --overwrite
2227

28+
echo "Red output: $RED_OUTPUT"
29+
2330

2431
echo "Doing the image math to create the NDVI image."
32+
2533
gdal_calc.py --calc="((A-B)/(A+B))" --type=Float32 -A $NIR_OUTPUT -B $RED_OUTPUT --outfile $NDVI_IMAGE --overwrite --NoDataValue=1.001
2634

2735

2836
echo "Color mapping the NDVI image."
2937
# this one creates the version with the alpha channel. It gets up uploaded.
30-
gdaldem color-relief $NDVI_IMAGE custom.txt $NDVI_COLOR -alpha
38+
39+
gdaldem color-relief $NDVI_IMAGE custom.txt $NDVI_COLOR -alpha
40+
41+
echo "Final output: $NDVI_COLOR"

0 commit comments

Comments
 (0)