Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It wasn't easy, but I solved it. Dockcross was using a deprecated tool named embedian. I have since made a pull request to Dockcross that uses a tool named crosstool-ng. However, there seems to be a bug either in OpenCV or Debian's pkg-config, and I had to use soft links to make the compilation possible. Here is how my dockerfile looks, feel free to use it:

FROM dockcross/linux-arm64
ENV DEFAULT_DOCKCROSS_IMAGE linux-arm64
# Set up CCache
RUN apt-get -y install ccache
ENV CCACHE_DIR=/.ccache
RUN mkdir /.ccache
RUN chmod 777 /.ccache

# Install required libraries
RUN apt-get -y install wget gawk gperf help2man texinfo gcc gperf bison flex texinfo make libncurses5-dev python-dev unzip
RUN apt-get -y install libavcodec-dev:arm64 libavformat-dev:arm64 libswscale-dev:arm64 libjpeg-dev:arm64 libpng-dev:arm64 libtiff-dev:arm64 libdc1394-22:arm64 libdc1394-22-dev:arm64 libv4l-dev:arm64 ffmpeg:arm64
RUN apt-get -y install --no-install-recommends libgtk2.0-dev:arm64
RUN apt-get clean --yes

# cd to /opencv and download OpenCV source
WORKDIR /opencv
RUN wget https://github.com/opencv/opencv/archive/3.4.0.tar.gz
RUN tar xvf 3.4.0.tar.gz

# necessary hacks
RUN ln -s /usr/include/dc1394/ /opt/x-tools/aarch64-unknown-linux-gnueabi/include/dc1394
RUN ln -s /usr/include/libavformat/ /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libavformat
RUN ln -s /usr/include/libavcodec/ /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libavcodec
RUN ln -s /usr/include/libavutil/ /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libavutil
RUN ln -s /usr/include/libswscale/ /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libswscale
RUN ln -s /usr/include/libv4l1.h /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libv4l1.h
RUN ln -s /usr/include/libv4l1-videodev.h /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libv4l1-videodev.h
RUN ln -s /usr/include/libv4l2.h /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libv4l2.h
ENV CXXFLAGS "-D__STDC_CONSTANT_MACROS"

# Build OpenCV
WORKDIR /opencv/opencv-3.4.0/build
RUN cmake -DWITH_V4L=ON -DWITH_1394=ON -DWITH_LIBV4L=ON -DINSTALL_C_EXAMPLES=OFF -DWITH_GTK=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_MAKE_PROGRAM=make -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_OPENGL=ON -DWITH_GDAL=ON -DWITH_XINE=ON -DBUILD_EXAMPLES=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF  -DWITH_FFMPEG=ON -DENABLE_NEON=ON -DBUILD_opencv_cudabgsegm=OFF -DBUILD_opencv_superres=OFF -DBUILD_opencv_cudalegacy=OFF -DBUILD_opencv_cudafilters=OFF -DBUILD_opencv_cudastereo=OFF -DBUILD_opencv_cudafeatures2d=OFF -DBUILD_opencv_shape=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_stitching=OFF -DBUILD_opencv_python_bindings_generator=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_cudaoptflow=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_calib3d=OFF -DBUILD_opencv_videostab=OFF -DBUILD_opencv_cudacodec=OFF -DBUILD_opencv_core=ON -DBUILD_opencv_cudaimgproc=OFF -DBUILD_opencv_dnn=OFF -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_cudev=OFF -DBUILD_opencv_video=OFF -DBUILD_opencv_cudawarping=OFF -DBUILD_opencv_cudaarithm=OFF -DBUILD_opencv_features2d=OFF -DBUILD_opencv_cudaobjdetect=OFF -DBUILD_opencv_flann=OFF -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE -DFFMPEG_LIBRARY_DIRS="/lib/aarch64-linux-gnu/" ..
RUN make -j8
RUN make install


WORKDIR /work

It wasn't easy, but I solved it. Dockcross was using a deprecated tool named embedian. I have since made a pull request to Dockcross that uses a tool named crosstool-ng. However, there seems to be a bug either in OpenCV or Debian's pkg-config, and I had to use soft links to make the compilation possible. Here is how my dockerfile looks, feel free to use it:

EDIT: Change dockerfile to reflect changed made in the Dockcross image:

FROM dockcross/linux-arm64
ENV DEFAULT_DOCKCROSS_IMAGE linux-arm64
# Set up CCache
RUN apt-get -y install ccache
ENV CCACHE_DIR=/.ccache
RUN mkdir /.ccache
RUN chmod 777 /.ccache

# Install required libraries
RUN apt-get -y install wget gawk gperf help2man texinfo gcc gperf bison flex texinfo make libncurses5-dev python-dev unzip
RUN apt-get -y install libavcodec-dev:arm64 libavformat-dev:arm64 libswscale-dev:arm64 libjpeg-dev:arm64 libpng-dev:arm64 libtiff-dev:arm64 libdc1394-22:arm64 libdc1394-22-dev:arm64 libv4l-dev:arm64 ffmpeg:arm64
RUN apt-get -y install --no-install-recommends libgtk2.0-dev:arm64
RUN apt-get clean --yes

# cd to /opencv and download OpenCV source
WORKDIR /opencv
RUN wget https://github.com/opencv/opencv/archive/3.4.0.tar.gz
RUN tar xvf 3.4.0.tar.gz

# necessary hacks
RUN ln -s /usr/include/dc1394/ /opt/x-tools/aarch64-unknown-linux-gnueabi/include/dc1394
RUN /usr/bin/aarch64-unknown-linux-gnueabi/include/dc1394 &&  \ 
ln -s /usr/include/libavformat/ /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libavformat
RUN /usr/bin/aarch64-unknown-linux-gnueabi/include/libavformat &&  \ 
ln -s /usr/include/libavcodec/ /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libavcodec
RUN /usr/bin/aarch64-unknown-linux-gnueabi/include/libavcodec &&  \ 
ln -s /usr/include/libavutil/ /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libavutil
RUN /usr/bin/aarch64-unknown-linux-gnueabi/include/libavutil &&  \ 
ln -s /usr/include/libswscale/ /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libswscale
RUN /usr/bin/aarch64-unknown-linux-gnueabi/include/libswscale &&  \ 
ln -s /usr/include/libv4l1.h /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libv4l1.h
RUN /usr/bin/aarch64-unknown-linux-gnueabi/include/libv4l1.h &&  \ 
ln -s /usr/include/libv4l1-videodev.h /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libv4l1-videodev.h
RUN /usr/bin/aarch64-unknown-linux-gnueabi/include/libv4l1-videodev.h &&  \ 
ln -s /usr/include/libv4l2.h /opt/x-tools/aarch64-unknown-linux-gnueabi/include/libv4l2.h
/usr/bin/aarch64-unknown-linux-gnueabi/include/libv4l2.h
ENV CXXFLAGS "-D__STDC_CONSTANT_MACROS"

# Build OpenCV
WORKDIR /opencv/opencv-3.4.0/build
RUN cmake -DWITH_V4L=ON -DWITH_1394=ON -DWITH_LIBV4L=ON -DINSTALL_C_EXAMPLES=OFF -DWITH_GTK=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_MAKE_PROGRAM=make -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_OPENGL=ON -DWITH_GDAL=ON -DWITH_XINE=ON -DBUILD_EXAMPLES=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF  -DWITH_FFMPEG=ON -DENABLE_NEON=ON -DBUILD_opencv_cudabgsegm=OFF -DBUILD_opencv_superres=OFF -DBUILD_opencv_cudalegacy=OFF -DBUILD_opencv_cudafilters=OFF -DBUILD_opencv_cudastereo=OFF -DBUILD_opencv_cudafeatures2d=OFF -DBUILD_opencv_shape=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_stitching=OFF -DBUILD_opencv_python_bindings_generator=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_cudaoptflow=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_calib3d=OFF -DBUILD_opencv_videostab=OFF -DBUILD_opencv_cudacodec=OFF -DBUILD_opencv_core=ON -DBUILD_opencv_cudaimgproc=OFF -DBUILD_opencv_dnn=OFF -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_cudev=OFF -DBUILD_opencv_video=OFF -DBUILD_opencv_cudawarping=OFF -DBUILD_opencv_cudaarithm=OFF -DBUILD_opencv_features2d=OFF -DBUILD_opencv_cudaobjdetect=OFF -DBUILD_opencv_flann=OFF -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE -DFFMPEG_LIBRARY_DIRS="/lib/aarch64-linux-gnu/" ..
RUN make -j8
RUN make install


WORKDIR /work