diff --git a/Dockerfile b/Dockerfile index 6b102ef..f3bb2f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,21 @@ -# Inherit from Heroku's python stack -FROM heroku/python:3 +# Inherit from Heroku's stack +FROM heroku/heroku:16 + +ENV PYTHON_VERSION python-3.6.2 # Create working directories -RUN mkdir -p /app/.heroku/opencv /tmp/opencv /tmp/leptonica /tmp/tesseract /tmp/python +RUN mkdir -p /app/.profile.d /app/.heroku/opencv /tmp/opencv /tmp/leptonica /tmp/tesseract /tmp/python # Copy files ADD Install-OpenCV /tmp/opencv ADD scripts/install_leptonica.sh /tmp/leptonica ADD scripts/install_tesseract.sh /tmp/tesseract -ADD requirements.txt /tmp/python + +RUN echo 'deb http://archive.ubuntu.com/ubuntu xenial multiverse' >> /etc/apt/sources.list && apt-get update # Install OpenCV WORKDIR /tmp/opencv/Ubuntu -RUN echo 'deb http://archive.ubuntu.com/ubuntu trusty multiverse' >> /etc/apt/sources.list && apt-get update -RUN ./opencv_latest.sh -RUN echo 'export PYTHONPATH=${PYTHONPATH:-/app/.heroku/opencv/lib/python3.5/site-packages}' > /app/.profile.d/opencv.sh -RUN echo 'export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/app/.heroku/opencv/lib/pkgconfig' >> /app/.profile.d/opencv.sh +RUN ./opencv_install.sh # Install leptonica for tesseract WORKDIR /tmp/leptonica @@ -25,16 +25,10 @@ RUN ./install_leptonica.sh WORKDIR /tmp/tesseract RUN ./install_tesseract.sh -# Prepare Python environment -WORKDIR /tmp/python -RUN /app/.heroku/python/bin/pip install -r requirements.txt - # Clean up RUN rm -rf /tmp/* # Onbuild ONBUILD WORKDIR /app/user -ONBUILD ADD requirements.txt /app/user/ -ONBUILD RUN /app/.heroku/python/bin/pip install -r requirements.txt ONBUILD ADD . /app/user/ diff --git a/Install-OpenCV/Ubuntu/cmake-detect-python.patch b/Install-OpenCV/Ubuntu/cmake-detect-python.patch deleted file mode 100644 index 97ad528..0000000 --- a/Install-OpenCV/Ubuntu/cmake-detect-python.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/cmake/OpenCVDetectPython.cmake b/cmake/OpenCVDetectPython.cmake -index f304a50..ad68d11 100644 ---- a/cmake/OpenCVDetectPython.cmake -+++ b/cmake/OpenCVDetectPython.cmake -@@ -236,10 +236,10 @@ find_python(3.4 "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR - - if(PYTHON_DEFAULT_EXECUTABLE) - set(PYTHON_DEFAULT_AVAILABLE "TRUE") --elseif(PYTHON2INTERP_FOUND) # Use Python 2 as default Python interpreter -+elseif(PYTHON2INTERP_FOUND AND BUILD_opencv_python2) # Use Python 2 as default Python interpreter - set(PYTHON_DEFAULT_AVAILABLE "TRUE") - set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}") --elseif(PYTHON3INTERP_FOUND) # Use Python 2 as fallback Python interpreter (if there is no Python 2) -+elseif(PYTHON3INTERP_FOUND AND BUILD_opencv_python3) # Use Python 2 as fallback Python interpreter (if there is no Python 2) - set(PYTHON_DEFAULT_AVAILABLE "TRUE") - set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON3_EXECUTABLE}") - endif() diff --git a/Install-OpenCV/Ubuntu/opencv_install.sh b/Install-OpenCV/Ubuntu/opencv_install.sh index 4e82e5b..a766259 100755 --- a/Install-OpenCV/Ubuntu/opencv_install.sh +++ b/Install-OpenCV/Ubuntu/opencv_install.sh @@ -5,14 +5,9 @@ # version - the version of OpenCV to be installed # downloadfile - the name of the OpenCV download file # dldir - the download directory (optional, if not specified creates an OpenCV directory in the working dir) -if [[ -z "$version" ]]; then - echo "Please define version before calling `basename $0` or use a wrapper like opencv_latest.sh" - exit 1 -fi -if [[ -z "$downloadfile" ]]; then - echo "Please define downloadfile before calling `basename $0` or use a wrapper like opencv_latest.sh" - exit 1 -fi +version=3.3.1 +downloadfile=opencv-3.3.1.zip + if [[ -z "$dldir" ]]; then dldir=OpenCV fi @@ -26,7 +21,8 @@ source dependencies.sh echo "--- Downloading OpenCV" $version mkdir -p $dldir cd $dldir -wget -O $downloadfile http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/$downloadfile/download + +wget -O $downloadfile https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/$downloadfile/download echo "--- Unarchiving OpenCV" $version echo $downloadfile | grep ".zip" @@ -36,9 +32,6 @@ else tar -xvf $downloadfile fi -echo "--- Patching OpenCV" $version -patch -p1 -d opencv-$version < ../cmake-detect-python.patch - echo "--- Installing OpenCV" $version cd opencv-$version mkdir build @@ -52,18 +45,18 @@ cmake \ -D BUILD_NEW_PYTHON_SUPPORT=ON \ -D BUILD_opencv_python2=OFF \ -D BUILD_opencv_python3=ON \ - -D INCLUDE_DIRS=${PYTHON_ROOT}/include/python3.5m \ + -D INCLUDE_DIRS=${PYTHON_ROOT}/include/python3.6m \ -D INSTALL_C_EXAMPLES=OFF \ -D INSTALL_PYTHON_EXAMPLES=OFF \ - -D PYTHON_INCLUDE_DIR=${PYTHON_ROOT}/include/python3.5m \ - -D PYTHON_INCLUDE_DIRS=${PYTHON_ROOT}/include/python3.5m \ - -D PYTHON_LIBRARIES=${PYTHON_ROOT}/lib/libpython3.5m.a \ - -D PYTHON3_INCLUDE_DIR=${PYTHON_ROOT}/include/python3.5m \ - -D PYTHON3_INCLUDE_DIRS=${PYTHON_ROOT}/include/python3.5m \ + -D PYTHON_INCLUDE_DIR=${PYTHON_ROOT}/include/python3.6m \ + -D PYTHON_INCLUDE_DIRS=${PYTHON_ROOT}/include/python3.6m \ + -D PYTHON_LIBRARIES=${PYTHON_ROOT}/lib/libpython3.6m.a \ + -D PYTHON3_INCLUDE_DIR=${PYTHON_ROOT}/include/python3.6m \ + -D PYTHON3_INCLUDE_DIRS=${PYTHON_ROOT}/include/python3.6m \ -D PYTHON3_EXECUTABLE=${PYTHON_ROOT}/bin/python \ -D PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.4m.so \ - -D PYTHON3_LIBRARIES=${PYTHON_ROOT}/lib/libpython3.5m.a \ - -D PYTHON3_PACKAGES_PATH=${PYTHON_ROOT}/lib/python3.5/site-packages \ + -D PYTHON3_LIBRARIES=${PYTHON_ROOT}/lib/libpython3.6m.a \ + -D PYTHON3_PACKAGES_PATH=${PYTHON_ROOT}/lib/python3.6/site-packages \ -D WITH_1394=OFF \ -D WITH_FFMPEG=OFF \ -D WITH_GSTREAMER=OFF \ diff --git a/Install-OpenCV/Ubuntu/opencv_latest.sh b/Install-OpenCV/Ubuntu/opencv_latest.sh deleted file mode 100755 index c867242..0000000 --- a/Install-OpenCV/Ubuntu/opencv_latest.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -. `dirname $0`/../get_latest_version_download_file.sh -if [ $? -ne 0 ]; then - exit $?; -fi -. `dirname $0`/opencv_install.sh diff --git a/Install-OpenCV/get_latest_version_download_file.sh b/Install-OpenCV/get_latest_version_download_file.sh deleted file mode 100644 index 70cba6d..0000000 --- a/Install-OpenCV/get_latest_version_download_file.sh +++ /dev/null @@ -1,19 +0,0 @@ -# Dan Walkes -# 2014-01-29 -# Find the latest version and download file link from the OpenCV sourceforge page - -version="$(wget -q -O - http://sourceforge.net/projects/opencvlibrary/files/opencv-unix | egrep -m1 -o 'Download opencv-([0-9](\.[0-9]+)+(-[-a-zA-Z0-9]+)*).zip?' | sed -e 's/Download opencv-\(.*\).zip/\1/')" -downloadfilelist="opencv-$version.tar.gz opencv-$version.zip" -downloadfile= -for file in $downloadfilelist; -do - wget --spider http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/$file/download - if [ $? -eq 0 ]; then - downloadfile=$file - fi -done -if [ -z "$downloadfile" ]; then - echo "Could not find download file on sourceforge page. Please find the download file for version $version at" - echo "http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/ and update this script" - exit 1 -fi diff --git a/README.md b/README.md index 9d1ba0e..e2baf38 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,16 @@ # Docker image for OCR and OpenCV service with Python3 on Heroku -This docker image has Python3, OpenCV and Tesseract features for Heroku. - -## Docker Hub - -- [supistar/docker-heroku-python3-opencv-tesseract](https://hub.docker.com/r/supistar/docker-heroku-python3-opencv-tesseract/) +This docker image is based on heroku:16 stack and has Python3, OpenCV and Tesseract features for Heroku. +Tesseract will be updated to v.4 when stable. ## Versions -- Python3: 3.5.1 (based heroku/python:3 docker image) -- OpenCV: 3.1.0 -- Tesseract: 3.04.01 -- Tessdata: 3.04.00 -- Leptonica: 1.73 - -## How to use this docker image - -1. Include this image by `FROM` command -2. Place your Python app/wsgi `requirements.txt` file on project root. -3. Run your app/wsgi application by `CMD` command - -Here is one of Dockerfile sample: -``` -# Base image -FROM supistar/docker-heroku-python3-opencv-tesseract - -# Add code -ADD ./webapp /app/user/webapp/ - -# Run application -WORKDIR /app/user/webapp -CMD gunicorn --bind 0.0.0.0:$PORT main:app --log-file - -``` +- Python3: 3.6.2 +- OpenCV: 3.3.1 +- Tesseract: 3.05.01 +- Tessdata: 3.05.01 +- Leptonica: 1.74.4 -## References -- [sugyan/docker-heroku-python-opencv](https://github.com/sugyan/docker-heroku-python-opencv) -- [hideyuki/docker-heroku-nodejs-opencv-tesseract](https://github.com/hideyuki/docker-heroku-nodejs-opencv-tesseract) +## Forked from +- [supistar/docker-heroku-python3-opencv-tesseract] +I fixed some stuff that didn't work for me, switched to a newer Heroku stack and updated all the packages above to the latest versions. \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 473a455..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -numpy==1.10.1 diff --git a/scripts/install_leptonica.sh b/scripts/install_leptonica.sh index d153e29..47646d6 100755 --- a/scripts/install_leptonica.sh +++ b/scripts/install_leptonica.sh @@ -1,7 +1,7 @@ #!/bin/sh # Variables -VERSION=1.73 +VERSION=1.74.4 NAME=leptonica-${VERSION} PREFIX=/app/.heroku/leptonica PROFILE=/app/.profile.d/leptonica.sh diff --git a/scripts/install_tesseract.sh b/scripts/install_tesseract.sh index 7a7573f..5b2b6c5 100755 --- a/scripts/install_tesseract.sh +++ b/scripts/install_tesseract.sh @@ -1,8 +1,8 @@ #!/bin/sh # Variables -OCR_VERSION=3.04.01 -DATA_VERSION=3.04.00 +OCR_VERSION=3.05.01 +DATA_VERSION=3.05.01 OCR_NAME=tesseract-${OCR_VERSION} DATA_NAME=tessdata-${DATA_VERSION} OCR_PREFIX=/app/.heroku/tesseract