Skip to content

Instantly share code, notes, and snippets.

@terasakisatoshi
Last active September 17, 2021 04:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terasakisatoshi/77e64396a5546338f606426d8d957706 to your computer and use it in GitHub Desktop.
Save terasakisatoshi/77e64396a5546338f606426d8d957706 to your computer and use it in GitHub Desktop.
How to build OpenCV.jl
FROM julia:1.5.3
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
python3 \
python3-distutils \
python3-numpy \
libgtk2.0-dev \
pkg-config \
git \
&& \
apt-get clean && rm -rf /var/lib/apt/lists/* # clean up
RUN git clone https://github.com/JuliaInterop/libcxxwrap-julia.git && \
cmake -DJulia_EXECUTABLE=`which julia` -S libcxxwrap-julia -B libcxxwrap-julia-build && \
cmake --build libcxxwrap-julia-build --config Release -j ${nproc} && \
cmake --build libcxxwrap-julia-build --target install && \
rm -r libcxxwrap-julia libcxxwrap-julia-build # clean up
RUN julia -e 'using Pkg; Pkg.add("CxxWrap"); Pkg.precompile()' && \
git clone --depth=1 -b 4.5.0 https://github.com/opencv/opencv.git && \
git clone --depth=1 -b 4.5.0 https://github.com/opencv/opencv_contrib.git && \
mkdir build && \
cmake -S ./opencv -B build \
-DJlCxx_DIR=/usr/local/lib/cmake/JlCxx \
-DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
-DWITH_JULIA=ON \
-DWITH_GTK=ON \
../opencv && \
cmake --build ./build --config Release -j ${nproc} && \
cp -r ./build/OpenCV ~/.julia/packages/ && \
cmake --build ./build --target install && \
rm -r ./build ./opencv opencv_contrib # clean up
# smoke test
RUN julia -e 'using Pkg; pkg"dev ~/.julia/packages/OpenCV"; Pkg.precompile(); using OpenCV'
@terasakisatoshi
Copy link
Author

terasakisatoshi commented Oct 31, 2020

Usage

  • It takes 76GB RAM during building OpenCV with -DJULIA_JULIA=ON
$ docker build -t opencvjl .
$ docker run --rm -it opencvjl 
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.5.3 (2020-11-09)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using OpenCV

julia>

You can run with pre-built Docker image via

$ docker run -it terasakisatoshi/opencvjl

@terasakisatoshi
Copy link
Author

The latest Dockerfile can be found at https://github.com/terasakisatoshi/OpenCVBuilder.jl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment